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
0
: 910 At:- 12/27/2017 10:58:00 AM
asp.net 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.

browser-cache-using-IIS

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.

<configuration> 
     <location path="showStockPrice.asp">     
       <system.webserver>        
         <caching>         
           <profiles>
             <add varybyquerystring="*"location="Any"
               duration="00:00:01" policy="CacheForTimePeriod"            
               extension=".asp">
           </profiles>
         </caching>
       </system.webserver>
     </location>
</configuration>

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

https://qawithexperts.com/article/asp.net/how-to-enable-caching-in-iis/24

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

## EXPIRES CACHING ##
<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"
</IfModule>
## EXPIRES CACHING ##

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

2
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
Or
Register directly by posting answer/details

Full Name *

Email *




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