How to Leverage browser caching for my CSS and js files.

How to Leverage browser caching for my CSS and js files?

Asked by:- RameshwarLate
: 6494 At:- 12/27/2017 10:58:00 AM IIS javascript CSS

1 Answers
profileImage Answered by:- Sam

 You can configure output caching using IIS for a specofic amount of time which you need to provide while configuring it like for 1 week, for one month, it depends on your need, here are the steps to do it using IIS

  • From the Start menu, click Administrative Tools, and then click Internet Information Services (IIS) Manager.
  • In the tree view on the left side, find your application/website.
  • Select the Output Caching menu item from the middle under "IIS".
  • In the right column, click Add in the Action menu. You can add your output caching rule here.
  • In the File name extension field, for example, type .php, and then select User-mode caching.
  • Click Advanced, and then select the Query string variable(s) check box.
  • Enter the appropriate variable(s) in the Query string variable(s) text box.


To Configure it using Web.Config file

You can also configure the caching feature in the local Web.config file, which is found in the content directory. Below is a sample of the configuration needed for a ShowStockPrice.asp page with a varyByQueryString parameter of * (meaning cache all unique variations of querystring parameters) and a timeout of 1 second.

     <location path="showStockPrice.asp">     
             <add varybyquerystring="*"location="Any"
               duration="00:00:01" policy="CacheForTimePeriod"            

There is another way using IIS explained in detail in this article

For Php users to enable it, add those lines to your .htaccess file:

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType application/javascript "access 1 month"
ExpiresByType application/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"

Make sure the mod_expires module is enabled on your server by running the following command via SSH access (or ask your host about this)

sudo a2enmod expires

At:- 12/27/2017 12:54:48 PM Updated at:- 12/27/2017 1:03:32 PM
thanks for well explained answer 0
By : pika - at :- 2/1/2018 8:19:00 AM

Login/Register to answer
Register directly by posting answer/details

Full Name *

Email *

By posting your answer you agree on privacy policy & terms of use