Link to home
Start Free TrialLog in
Avatar of nzinsli
nzinsliFlag for United States of America

asked on

browser caching

In regards to forcing a browser to download a new copy of a file that it would typically cache, would adding a parameter to the url have the same effectiveness as changing the filename itself? ie: file.css?v=123 vs file123.css
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

That works if it constantly changes.  The problem of course is getting the browser to start downloading that version in the first place.  As long as the original pages are still cached with the original file name, the browser will still keep using those versions until they expire from the local cache.
Avatar of nzinsli

ASKER

The browser shouldn't use the cached file though if the html is calling for a new filename in the code tho, correct? I was just curious as to if one method was preferred over another.
The problem usually is that the HTML file is cached and the new file name for the CSS doesn't get picked up until the HTML file in the cache expires.
Avatar of nzinsli

ASKER

While that may be true, I can't say I've ever had a problem with the html being cached or not showing the new version when loading. Wouldn't the browser look at the last modified date on the server version before rendering the cached html? Include files on the other hand...is where my question lies. If you suppose that it is not loading a cached html, is there any difference for caching if I call an included css file with file.css?v=123 or file-123.css?
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nzinsli

ASKER

"If the link is "file.css?v=124" next time, then there is." ...If the version # changes, then there is a difference??

I'm glad you brought up modified date. The reason this all came about, is I'm going to be dynamically building the file include list via literals in vb.net. The version # is going to be read from a xml file that gets updated when one of these files is updated, so the user is more assured to get the latest code w/o refreshing. But, since the actual html file isnt being edited & saved, the modified date wont change. I wonder if this will cause an issue...hmmm...
The browser cache is done by the complete URL including the query string.  Adding the current time is a standard technique in AJAX to prevent the browser from just returning info from it's cache.

Look here for info on preventing caching in IIS: http://www.iis.net/ConfigReference/system.webServer/staticContent/clientCache