Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    May 2008
    Posts
    12
    Thanks
    0
    Thanked 2 Times in 2 Posts

    [Solved] JavaScript generation script

    Hello everyone.

    I've been looking for a good JavaScript discussion forum for a while. I only just found this one - looks pretty good .

    Here's what I want to discuss:

    It makes symantic sense to put each separate object in it's own JavaScript file. An example of this is the rather over-namespaced YUI JavaScript library.

    However when you get into creating large JavaScript applications you can be dealing with many different objects, meaning that you could be making 15 or 20 links to external JavaScript file. Now since each new connection takes extra time this can slow down the loading of a web page quite significantly, and if these files are on every page of a website this could mean the whole site running considerably slower.

    Code:
    <head>
      <title>My page</title>
      <script type="text/javascript" src="/js/ParentObject.js"></script>
      <script type="text/javascript" src="/js/ChildObject1.js"></script>
      <script type="text/javascript" src="/js/ChildObject2.js"></script>
      <script type="text/javascript" src="/js/AnotherObject.js"></script>
      <script type="text/javascript" src="/js/SomethingElse.js"></script>
      ....
    </head>
    It seems to me that the best solution to this is to write a CGI script that can pull the different JavaScript files together and serve them as one file, thus only one connection has to be made to get all the JavaScript, but the JavaScript can still be separated into logical files:

    Code:
    <head>
      <title>My page</title>
      <script type="text/javascript" src="/scripts/loadJavaScript.cgi?ParentObject.js&ChildObject1.js&ChildObject2.js&AnotherObject.js&SomethingElse.js" />
    </head>
    Of course the URL could get rather long. So maybe you could include configurations, and tell it to load "configuration1" of the JavaScript files or something (e.g. /scripts/loadJavaScript.cgi?config=1) and then this would allow for the output of a configuration to be cached, cutting down on server-side processing time.

    Anyway, I cannot be the first person to think of this. It's a well known problem so there must be a common solution. So my question is, how do people normally solve this problem? And is there a standard script similar to the one disctribed above that I can use? Or is there a better solution?

    Ta,
    Robin.
    Last edited by nottRobin; 05-07-2008 at 04:37 PM.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,853
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New Coder
    Join Date
    May 2008
    Posts
    12
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Cool thanks that is exactly what I was talking about. And it looks like they've done it in almost exactly the way I was suggesting.

    Out of interest, do you use this sort of technique?

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,853
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    I had tried it, and got it worked. But then after I removed, since I had some css& javascript files in some other directories other than /css & /javascripts , so I felt it hard to control. But I'm confident
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

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