2

Assuming I have a page with several subpages which do not share the same scripts, what is the best policy concerning server load and performance?

Right now I have included all javascript files/plugins in all pages. But for example, subpage1 is the only one using GoogleMaps API, subpage2 is the only one using a lightbox plugin, etc.

My page can be crowded sometimes so I want to minimize server load where ever possible. So, what's best? Does it even matter?

3
  • 3
    Why not including the general assets in your layout/main page markup and specific assets in their own pages markup (the sub-pages you've mentioned). Commented Aug 3, 2013 at 16:09
  • The exact same question has been asked on SO before, but I can't find it at the moment Commented Aug 3, 2013 at 16:16
  • I thought so but I couldn't find other questions about it... ;) Commented Aug 3, 2013 at 20:57

3 Answers 3

2

Consider moving static content off your servers.

For public JS files like jquery, I would simply link to the public sites so that Google or whoever serves them. That will keep load off your servers, plus their CDN has a chance to serve the files from a site close to the client, making loading faster.

Another option is to host your static content like JS/CSS/PNG in AWS S3.

Sign up to request clarification or add additional context in comments.

2 Comments

So do you suggest the following: use Google servers where possible; and only add the javascript files which are needed for each page/template?
Basically, yes. Anything publicly sourced (like jquery), I would reference from Google CDN. I would minify where possible, ensure that JS files were cacheable by the client, measure the actual performance to identify slow parts, limit JS inclusion to what was necessary on a page. Some more ideas here: developer.yahoo.com/performance/rules.html and here: developers.google.com/speed
1

Your index.html should probably look something like this:

<!--#include virtual="header.html" -->
<!--#include virtual="main.html" -->
<!--#include virtual="footer.html" -->

Where all your necessary assets are in the header.html file and as-needed assets are in the main.html file(s).

(Of course, you could use the PHP or Javascript / jQuery version just as easily.)

Comments

0

It depends on your server configuration, actually.

If it allows status 304 as response, that wouldn't be much of a bother, since the content isn't sent back.

If the server doesn't even send some headers like Cache-Control: must-revalidate, some browsers can even avoid the request altogether.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.