Solved

browser caching

Posted on 2012-03-12
7
278 Views
Last Modified: 2012-05-07
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
0
Comment
Question by:nzinsli
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 37710967
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.
0
 

Author Comment

by:nzinsli
ID: 37711015
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.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 37711270
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.
0
Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

 

Author Comment

by:nzinsli
ID: 37714857
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?
0
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 37716044
"file.css?v=123 or file-123.css"  No difference.  If the link is "file.css?v=124" next time, then there is.  It has appeared that some times the browser only looks at the last-modified date of the HTML file and if it hasn't changed, then it loads CSS and javascript from cache.  I think that maybe that has improved in the last year or two now that you mention it because it hasn't been as much of a problem for me recently.  But I've also upgraded my web server twice in the last year.
0
 

Author Comment

by:nzinsli
ID: 37716213
"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...
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 37716370
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
0

Featured Post

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
specific navigation button disappears on mobile devices 1 79
help thx 6 34
Print a <div></div> only 5 52
object method as an event handler 8 72
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question