Enable Browser Caching For Static Resources
To improve the site performance, I'm adding following http headers in IIS 7.5. Expires: Sun, 29 Mar 2020 00:00:00 GMT and Cache-Control: Public I'm adding these headers for image
Solution 1:
Your header shows that you add a new value but you need to replace the existing one
Cache-Control:no-cache, no-store,Public
Expires:-1,Sun, 29 Mar 2020 00:00:00 GMT
no-cache, no-store
stands for no cache and -1
says that the content is already expired.
Instead of doing it from the code you can easily set it in the root web.config file as
<location path="images">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseExpires"
httpExpires="Sun, 29 Mar 2020 00:00:00 GMT" />
</staticContent>
</system.webServer>
</location>
</configuration>
where images is a name of your directory
or add dedicated web.config file directly in the target directory
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseExpires"
httpExpires="Sun, 29 Mar 2020 00:00:00 GMT" />
</staticContent>
</system.webServer>
</configuration>
You can also use cacheControlMode="UseMaxAge" and set specific time of expiration
Example to set expiration in 7 days
<clientCache cacheControlMode="UseMaxAge"
cacheControlMaxAge="7.00:00:00" />
Read more http://msdn.microsoft.com/en-us/library/ms689443.aspx
Post a Comment for "Enable Browser Caching For Static Resources"