Kevin
Kevin

Reputation: 79

Loading time with multiple copies of the same JS file

I am working with an application that is built in frames, yeah, the old ones, and I was thinking about adding a main.js file to all my pages to get some consistency. Assuming the file gets cached so we don't need to download it every time from server, and the script is loading on 3-5 pages/frames simultaneously, are there other loading time considerations that I should be taking into account?

I was thinking there may be extra time for reading the file or parsing on page load or something of that sort.

Upvotes: 1

Views: 420

Answers (1)

Scott Marcus
Scott Marcus

Reputation: 65835

Yes, the file will cache as long as it's file name or date stamp doesn't change.

The only performance consideration is that there will be an extra HTTP request made, but that's negligible.

Make sure that your <script> reference occurs in the correct location in the .html file. If it relies on HTML elements, place it just before the closing body tag so that by the time the browser downloads and begins to execute the file, the DOM will have been built.

If it doesn't reference elements, but does some general processing that is needed early on, then place it in the head section.

Make sure that your site has an SSL certificate and that your link to the script (as well as all other links) use the https:// protocol or users with updated versions of Chrome won't get the file served as Chrome has put the hammer down on http://.

And, just because I have to... Get rid of those frames! They're not even valid in HTML5.

Upvotes: 3

Related Questions