www.webdeveloper.com
Results 1 to 6 of 6

Thread: Does referencing a javascript 2 times in a page downloads it 2times

  1. #1
    Join Date
    Aug 2009
    Posts
    2

    Does referencing a javascript 2 times in a page downloads it 2times

    Hi,
    I have an external js file which is being called and referenced in a page.
    Now if i reference the same file 2 or 3times in the page will it download the same file 2 -3times when user is browsing through the site.
    Or when it has downloaded once and see's a reference to same file at same location it won't download the file second time?

    I hope you have understood my query.

    Thanks,
    Huzefa

  2. #2
    Join Date
    Jan 2005
    Location
    Frankfort, KY, USA
    Posts
    6,167
    If you've linked to a javascript file in the <head> section like this:
    Code:
    <script type="text/javascript" src="file.js"></script>
    It's only "downloaded" once, no matter how many times it is used in the coding.

  3. #3
    Join Date
    Aug 2009
    Posts
    2
    No not like this...i will explain

    I am a .Net developer so in my site i have something like master page and child page. So when a page is rendered on screen its a combination of both master and child page.
    Now i can keep this reference of .js file like
    <script type="text/javascript" src="file.js" />
    in master as well as child page.
    so now when the actual page is rendered onto the screen then it contains 2 references to same file i.e. file.js

    So now in this case will it be downloaded 2 times or only 1 time.

    Thanks
    Huzefa

  4. #4
    Join Date
    Jan 2005
    Location
    Frankfort, KY, USA
    Posts
    6,167
    Normally, a "Master page" is the template, with the stylistic HTML and cross-site coding, applicable to any child page; that child "page" really being just some .NET coding that creates unique main content or an event. Used correctly, the Master would have the <head> section of the template, meaning your js., and then negating the need of linking in your child page.

  5. #5
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    what do you mean by a "child page"? A page opened with a window.open() method?

  6. #6
    Join Date
    Aug 2007
    Posts
    3,767
    It will not download the page again, as in actually contact the server to get it, it will be referenced in the cache, so the copy that has already been downloaded. But from the point of view of variables, it might as well be downloaded again, it is a new copy of the same file.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles