How to invalidate browser cache using only configuration on the web server?

For a long time I have been updating pages ASP.NET

on the server and have never found a way to correctly get the changes to show up in files like CSS

and images

.

I know if you add something to URL

, the browser will think the file is different:

<img src="/images/myLogo.png?v=1"/>

      

or perhaps changing its name:

<img src="/images/myLogo.v1.png"/>

      

Unfortunately it doesn't look the right way. In case I use App_Themes

, the files in this folder are automatically inserted into the page in such a way that I cannot easily change URL

.

So my question is:

When I publish de ASP.NET Application

to the server, what's the correct way to signal IIS

(and then notify the browser) that the file has changed? Is it not automatic? Should I change any configuration in IIS

or maybe do some "embellishments" in the code?

I've tried a lot of questions here, as "an ASP.NET - the Invalidate browser cache" , How to update your browser cache image? , "Process cached images? How do I get the browser to show the new version?" and even "What is an elegant way to force browsers to reload cached CSS / JS files?" but none of them actually do the other aproach in a different way that you have to handle it manually in instead of config IIS

or ASP.NET

.

The closer I can find "Ask the browser to cache our images (ASP.NET/IIS)" , where they set an expiration date but are not based on the fact that the files were updated. Instead, they used days or hours to cache these files so that they were updated even if there was no change.

I want to know if it suggests IIS

or ASP.NET

something related to automatically send to the browser that the files have changed. Is this embedding possible?

+3


source to share


1 answer


Parameters required to update browser element , caching :

  • Change the file name
  • Add URL parameter
  • Put it in the cache for a limited time (like a few hours)
  • Compare the creation date .
  • Alarm with eTag .

With three two, you avoid one server call for each item, but the third option downloads it again after a while.

With the rest, you have to make one call to the server to see if it needs to be downloaded again.



So you cannot have everything here, there is no right way, and you have to choose what is best for you and what you can do. The faster the client perspective is options (1) and (2).

The direct answer to your question is using an eTag or comparing the creation date of the file , but you lose this way, the call to the server , you only win the size of what is returned.

Some more links:
http eTag
How to support ETags in ASP.NET MVC? Configuring ETags with the Http Module in asp.net
How do I control web page caching in all browsers?
Jquery getScript caching

and you can find even more.

+1


source







All Articles