We can specify the browsers, how long time to keep css ,JS and images stored locally using the .htaccess file i.e( leverage browser caching of static assets). Using google PageSpeed Insights, we can find out how to make our web pages faster on all devices, after giving the web page URL on the text box and clicking the analyze button.
You have to add the following text to the .httaccess file. It will instruct the browser to load previously downloaded resources from the local disk rather than over the network.
Leverage browser caching htaccess code:
# BEGIN EXPIRES
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault"access plus 10 days"
ExpiresByType text/css"access plus 1 week"
ExpiresByType text/plain"access plus 1 month"
ExpiresByType image/gif"access plus 1 month"
ExpiresByType image/png"access plus 1 month"
ExpiresByType image/jpeg"access plus 1 month"
ExpiresByTypeapplication/x-javascript "access plus 1 month"
ExpiresByTypeapplication/javascript "access plus 1 week"
ExpiresByTypeapplication/x-icon "access plus 1 year"
</IfModule>
# END EXPIRES
But for Godaddy windows hosting, it will not work. So,you need to create caching rules in web.config configuration file to enhance the website speed.
System webserver caching:
<configuration>
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseExpires"
httpExpires="Tue, 19 Jan 2038 03:14:07 GMT" />
</staticContent>
</system.webServer>
</configuration>
Also add the following code at the top of the .htaccess file.
<IfModule pagespeed_module>
ModPagespeed on
# using commands,filters etc
</IfModule>
Post your comments / questions
Recent Article
- How to add two numbers in Android Studio? | Source Code
- FindViewByID returns null in android studio -SOLVED
- Saving changes is not permitted in SQL SERVER - [SOLVED]
- Restore of database failed. File cannot be restored over the existing. -[SOLVED]
- One or more projects in the solution were not loaded correctly in Visual Studio 2019 | FIXED
- How to find Laptop's Battery Health?
- SOLVED-Related Field got invalid lookup: icontains error in Django
- How to enable Search Feature in Django admin?
Related Article