views:

467

answers:

3

Hi there,

Can anyone help? I have been designing a site using Javascript but the rest of the html content is static ie. images etc

When i load my page in Firefox i have to clear the cache..

I remember a long time ago there was something you could add to the html to force a reload.

My question is, is this a good thing? I presume it caches for a reason i.e to cahce images etc.. But this causes my pages not to refresh

And how to do it?

Really appreciate any feedback

+1  A: 

If you want only the js to be loaded afresh everytime, and leave everything else to load from cache, you can add a version number to the js include line like so:

<script src="scripts.js?v=5643" type="text/javascript"></script>

Change the version number (?v=num) part each time you change the js file. This forces the browser to get the js file from the server.

Note: Your actual file name will be the same - scripts.js

For disabling cache for all files, if you're using apache, put this in your httpd.conf

<Directory "/home/website/cgi-bin/">
    Header Set Cache-Control "max-age=0, no-store"
</Directory>

You can also put a meta tag on your html like so:

<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />

More info on this here

trex279
thanks .. but also need it for my html files too
mark smith
A: 

For web pages you can how the page is cached in the HTTP Header. You should look at Expires if you have a particular date for the cache to expire or Cache-Control for dynamic expiration based on when the page was requested. Here's a pretty good tutorial that covers how cache works and covers set up on the major web servers.

Jeremy
A: 

Try pressing Control + F5 when you load your page in FireFox-- this should clear your browser's cache of the page and reload cleanly for you.

Cuga