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
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
Share Improve this question edited Jan 28, 2016 at 19:20 Pieter Goosen 55.4k23 gold badges116 silver badges210 bronze badges asked Jan 28, 2016 at 18:55 Riyajul IslamRiyajul Islam 11 bronze badge 2- 1 A Google search for "WordPress expiry headers" will yield some useful results. – Milo Commented Jan 28, 2016 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 Commented Jul 6, 2019 at 12:13
2 Answers
Reset to default 3For WordPress Website optimization you should take a look at: https://codex.wordpress/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/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>
<FilesMatch ".(xml|txt)$">
Header set Cache-Control "max-age=3600, public, must-revalidate"
</FilesMatch>
<FilesMatch ".(html|htm)$">
Header set Cache-Control "max-age=3600, must-revalidate"
</FilesMatch>
# 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
</FilesMatch>
</IfModule>
Pagespeed also offer instructions on the other factors. You should follow them.
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:
E.g.
## 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 ##
or if you're using Nginx it can be included within your configuration file:
E.g.
server {
listen 80;
server_name example;
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;
}
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745341201a4623334.html
评论列表(0条)