Enable leverage browser caching for speed optimization!
leverage browser caching is important factor to grow website page speed and decrease load time.
When we check the website in pagespeed tools like gtmetrix and google page speed we get this issue in speed check results.
When we check the website in pagespeed tools like gtmetrix and google page speed we get this issue in speed check results.
we have to enable leverage browser caching for images, text files etc so we can set expiry time for all these. It can increase speed by 10%.
To enable leverage browser caching for speed optimization in .htaccess file, you can add the following code:
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType text/html "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 2 days"
</IfModule>
## EXPIRES CACHING ##
The ExpiresActive On directive enables the Expires headers.
The ExpiresByType directives specify the expiration time for specific file types. In this example, we set a 1-year expiration time for image files (JPG, JPEG, GIF, PNG, and ICO), a 1-month expiration time for CSS, JavaScript, and PDF files, and a 2-day expiration time for all other file types.
The ExpiresDefault directive sets the default expiration time for files that do not match any of the previous directives.
You can modify the expiration times according to your specific needs. Once you've added this code to your .htaccess file, save the file and test your website to verify that caching is enabled and that the expiration times are set correctly.
Note that the mod_expires module must be enabled on your server for this code to work. You can check whether the module is enabled by adding the following code to your .htaccess file:
<IfModule mod_expires.c>
# mod_expires is enabled
</IfModule>
If the module is not enabled, you will need to enable it in your server configuration.
Post a Comment