I have a WordPress website. I've tested it for speed test with google tools, but I see some of errors like this:

Leverage browser caching Setting an expiry date or a maximum age in the HTTP headers for static resources instructs the browser to load previously downloaded resources from local disk rather than over the network. Leverage browser caching for the following cacheable resources:

So how can I solve this errors and seed up my site. Please give me a better way to fix it by any coding or by any Plugins.

You can see it live here

  • 1
    A Google search for "WordPress expiry headers" will yield some useful results. – Milo Jan 28 '16 at 19:29
  • It is better and very easy to use this WP add expires headers plugin for adding expires headers and gzip compression. It will create browser cache for files format you select and expiry time accordingly. But make sure file formats you choose not much dynamic by nature otherwise it can cause you problem. – General User Jul 6 at 12:13

For WordPress Website optimization you should take a look at: https://codex.wordpress.org/WordPress_Optimization

I took a look at your pagespeed report and the main thing there are the images you are using. There are many plugins that can optimize them for you. I like this one in particular: https://wordpress.org/plugins/imsanity/

As per the server cache, you can either try the popular cache plugins or ask a sysadmin to optimize these options for you on the server level.

In my case. Using Apache 2.4 I have this configuration in my pre_virtualhost_global.conf:

# Cache Control Settings for one hour cache
<FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=3600, public"

<FilesMatch ".(xml|txt)$">
Header set Cache-Control "max-age=3600, public, must-revalidate"

<FilesMatch ".(html|htm)$">
Header set Cache-Control "max-age=3600, must-revalidate"

# Mod Deflate performs data compression
<IfModule mod_deflate.c>
<FilesMatch ".(js|css|html|php|xml|jpg|png|gif)$">
SetOutputFilter DEFLATE
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch bMSIE no-gzip

Pagespeed also offer instructions on the other factors. You should follow them.

  • where can i put this codes? – Riyajul Islam Jan 29 '16 at 21:06
  • This is a sample code, not for you to install on your environment since I know nothing about it. You should talk to the sysadmin of your hosting. – Emanuel Rocha Costa Jan 29 '16 at 21:09

I would suggest reading this article which helps better explain the page speed recommendation of "leverage browsing caching". You can set your desired expires header either in your .htaccess file:


<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"

or if you're using Nginx it can be included within your configuration file:


server {
    listen       80;
    server_name  example.com;

    location / {
        root   /var/www/example;
        index  index.html index.htm;

    location ~*  \.(jpg|jpeg|gif|png)$ {
        expires 365d;

    location ~*  \.(pdf|css|html|js|swf)$ {
        expires 30d;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.