7

i was wondering - when using jQuery (or any other javascript include) in my web, does the browser cache it after the first download for all all pages (i assume yes) or will it download it every time?

2nd, when the user quits the browser and starts it again (for loading my website), will the jquery js file still be cached or will it completely download again?

thx

1
  • You might consider going through your questions and picking answers, you'll be more likely to get responses. Commented Aug 17, 2010 at 1:38

5 Answers 5

9

This depends on the browser and on how your server is set up. Have a look at the headers sent by the server along with the file (you can use a tool like Firebug to look at the headers). A good idea is to use the jQuery file hosted by google, since many other sites (including stackoverflow) use the same file. Then the browser can cache that file and never download it from your server. This page has a list of files hosted by google, and this page explains how to properly set your server up to (tell your browser to) cache files.

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

Comments

3

1: Yes, the browser caches all jscript/css includes

2: If the user does not clear his/her cache. Yes it will still be in the cache of the browser, even after closing and reopening it.

Comments

3

If your webserver serves jquery.js using a proper expires header, then yes, the browser will cache it.

http://developer.yahoo.com/performance/rules.html#expires

Comments

3
  1. Yes the scripts will get cached between page views, along with the CSS files and images.

  2. Yes as well, in general. The cache is normally maintained between browser restarts.

Comments

2

It will typically not be downloaded again, but unless your server explicitly tells the browser to cache it for a while, then it will send a request on each page load asking "was jquery.js updated?" which is almost as slow as just downloading it again.

You can test how it works on your site with Google's Page Speed or Yahoo's YSlow.

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.