Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery/javascript caching question

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

like image 694
Fuxi Avatar asked Feb 14 '10 10:02

Fuxi


4 Answers

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.

like image 60
Marius Avatar answered Sep 21 '22 06:09

Marius


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.

like image 39
Marvin Smit Avatar answered Sep 18 '22 06:09

Marvin Smit


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

like image 25
cherouvim Avatar answered Sep 18 '22 06:09

cherouvim


  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.

like image 36
Daniel Vassallo Avatar answered Sep 18 '22 06:09

Daniel Vassallo