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 Enable Virtualization in BIOS Security Settings in Intel Processors For Android Studio?
- Dependency 'androidx.activity:activity:1.8.0' requires libraries and applications that depend on it.
- AttributeError: 'NoneType' object has no attribute 'get_text' - Python
- ModuleNotFoundError: No module named 'openpyxl' - Python
- How to get thumbnail from vimeo video URL in Python?
- Remove all special characters, punctuation except spaces from string - Python
- OSError: cannot write mode RGBA as JPEG- Python
- expected str, bytes or os.PathLike object, not JpegImageFile - Python
Related Article