How to Leverage Browser Caching

Swostik's Blog

This is How to Leverage Browser Caching on WordPress Sites, by adding the below code to your .htaccess file.

[php]## 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 text/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 ##[/php]

View original post

Advertisements

How to Leverage Browser Caching

Wordpress

This is How to Leverage Browser Caching on WordPress Sites, by adding the below code to your .htaccess file.

[php]## 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 text/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 ##[/php]

Specify a Vary Accept-Encoding header

Wordpress

This is how you will Specify a Vary Accept-Encoding header

Open your .htaccess file and add the below code and you are done.

For Apache/.htaccess :
[php]# BEGIN Specify a Vary: Accept-Encoding
<IfModule mod_headers.c>
<FilesMatch ".(js|css|xml|gz|html)$">
Header append Vary: Accept-Encoding
</FilesMatch>
</IfModule>
# END Specify a Vary: Accept-Encoding[/php]

For Nginx :
[php]gzip_vary on[/php]

For IIS :
[php]<system.webServer>
<httpProtocol>
<customHeaders>
<remove name="Vary"></remove>
<add name="Vary" value="Accept-Encoding"></add>
</customHeaders>
</httpProtocol>
</system.webServer>[/php]

Remove query strings from static resources

Wordpress

For all the WordPress users who are annoyed by query strings in the url and have reduced page scores for having links like :

[box type=”note” border=”full” icon=”none”]/wp-includes/js/jquery/jquery.js?ver=1.4.2[/box]

It is now editable.

So, how to Remove query strings from static resources?

Answer : Place the below code into your functions.php file in between those php tags.
ie. Appearance –> Editor –> your theme’s function.php

[php]function _remove_script_version( $src ){
$parts = explode( ‘?’, $src );
return $parts[0];
}
add_filter( ‘script_loader_src’, ‘_remove_script_version’, 15, 1 );
add_filter( ‘style_loader_src’, ‘_remove_script_version’, 15, 1 ); [/php]

Note :
[box type=”alert” border=”full” icon=”none”]1. Be careful while editing, if you don’t place the code in the right place you may break your code.
2. The above piece of code might not work in case of plugins having query strings.[/box]

Live Blog : 2013 Google I/O Keynotes

2013-google-io-keynotes

2013 Google I/O Keynotes

[liveblog]