SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    501
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Including a javascript file inside of another javascript file

    i don't believe there is a way to do this naturally in javascript (like an include() function) but i've seen toolkits like dojo use a custom built require function. i'm just curious as to how i could pull in a javascript file into another javascript file.

  2. #2
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    501
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nevermind, figured it out. :P

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2004
    Location
    Third Stone From The Sun
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by NokX View Post
    nevermind, figured it out. :P
    This is no small issue here.

    It makes sense that javascript should have this feature, but it doesn't. Behavior can only be bound in the content layer. Doesn't make sense, but that's what we're stuck with.

    the way dojo does it doesn't make much sense to me. Using eval makes it very hard to debug. append a script tag - it is a much better way to do it because you don't have to deal with trying to figure out eval'd js.

    Increasing the number of files and also loading them in JS can cause a performance hit.

    You might want to consider making a script or ANT task, or filter to combine your files or the server. This will reduce number of HTTP requests. The more files combined, the greater the savings. On my last contract, we had sometimes 30 files per page. Many of these were very small files, but added to the page overhead and slowed loading down.

    I should note that it is important to use the Single Responsibility Principle (SRP) and do not use tight coupling. Too many web developers use horrendous design or no design at all. How many times have you seen "common.js" or "functions.js", I know I've written lots of code like that in the past. Even the YUI packages things up into a "utils" namespace (at least it's not one file though). Well, that is just the way most people do things and it is not good. Breaking things up properly makes it easier to test and manage the code. No copy-paste-and-see-if-it-works. No "all implementation code".

    Creating a build process to combine files can improve performance to a greater degree when there are many files loaded. If the files are referenced in the JS, make sure that you use a logical directory/package structure.
    My outdated site is down for a while now.

  4. #4
    SitePoint Enthusiast
    Join Date
    Feb 2004
    Location
    Third Stone From The Sun
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    by the way, I like your avatar. I can only play old games like pac man, donkey kong. I am clueless about new games and I think they look a little too real.
    My outdated site is down for a while now.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •