How to Speed up WordPress Leveraging Browser Caching via .htaccess

Leverage browser caching to make your webpages faster. If you can leverage browser caching, you can increase website speed considerably. As Google starts considering site speed as a SEO parameter,webmasters can leverage browser caching to improve site speed and get better search engine rankings.
Getting rid of ETag
First of all, we need to disable ETag header since we are going to use Expires. ETag technology is known as slow and problematic – even YSlow complains about it.
Add to .htaccess: (located at blog’s root location)
|
1
2
3
|
Header unset Pragma
FileETag None
Header unset ETag
|
Other must read:
- 5 Useful Tricks To Speed Up WordPress & Boost Performance
- 9 essential WordPress resources you may have missed
Why browser caching?
If you set an expiry date or a maximum age in the HTTP headers for static resources, modern browsers will load previously downloaded static resources like images, css, javascript, pdf, swf etc. from local disks rather than over the network.
So if you configure your web server to set caching headers and apply them to all cacheable static resources, your site will appear to load much faster. Add below to .htaccess
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
## 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 text/html “access 1 month”
ExpiresByType application/pdf “access 1 month”
ExpiresByType text/x–javascript “access 1 month”
ExpiresByType application/x–shockwave–flash “access 1 month”
ExpiresByType image/x–icon “access 1 year”
ExpiresDefault “access 1 month”
</IfModule>
## EXPIRES CACHING ##
|
What this does is adding far future expires header (make sure mod_expires is loaded in your apache config if you have problems) to your static content (images, js, css, etc).
Compress Components
Compressing things always ends up making them smaller and load faster, so implementing some form of compression on your components is a must. This optimization step might not work for you if your server does not have either mod_deflate or mod_gzip installed as part of Apache.
|
1
2
3
|
<FilesMatch “\\.(js|css|html|htm|php|xml)$”>
SetOutputFilter DEFLATE
</FilesMatch>
|
|
1
2
3
4
5
6
7
8
9
10
|
<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi–script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x–javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content–Encoding:.*gzip.*
</IfModule>
|
List of all WordPress Articles: http://crunchify.com/category/wordpress/









