Forum Moderators: open

Message Too Old, No Replies

Add Expires headers into WordPress

         

toplisek

12:23 pm on Sep 22, 2021 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have added
## EXPIRES HEADER 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 image/svg "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType application/javascript "access 1 month"
ExpiresByType application/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 3 days"
</IfModule>
## EXPIRES HEADER CACHING ##


It still shows up a warning message [tools.pingdom.com...] and points 56 not 100

Web pages are becoming increasingly complex with more scripts, style sheets, images, and Flash on them. A first-time visit to a page may require several HTTP requests to load all the components. By using Expires headers these components become cacheable, which avoids unnecessary HTTP requests on subsequent page views. Expires headers are most often associated with images, but they can and should be used on all page components including scripts, style sheets, and Flash.

robzilla

1:11 pm on Sep 22, 2021 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Any advice that references Flash should probably not be taken very seriously in 2021.

Frankly, Pingdom is not a great tool for testing your website speed. Certainly don't apply any changes to your site only because their tool (or any other) suggests so. Still, it's generally a good idea to add expiry headers to some file types, if you understand the effects. ExpiresDefault "access 3 days", for example, will allow 3-day browser caching for your HTML pages, which may not be what you want if you're using WordPress (unless WordPress overrides the headers, which is also possible).

It's important to know which resources don't have expiry headers, and Pingdom doesn't give you that information. I believe PageSpeed Insights does, so maybe give that a try. Or open the Network tab of your browser's Developer Tools and have a look at the headers yourself.

not2easy

1:27 pm on Sep 22, 2021 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



I agree with robzilla on Flash, no one is using flash for awhile now so you can snip that line.

I hope this code that was posted here was not added to your site using JavaScript/AJAX? We do have a WordPress forum here: [webmasterworld.com...]

lucy24

4:29 pm on Sep 22, 2021 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



ExpiresDefault "access 3 days", for example, will allow 3-day browser caching for your HTML pages, which may not be what you want if you're using WordPress
If you’re using WordPress, it’s very likely you don’t have HTML pages. Except possibly error documents, which you would hope visitors don’t require more than once in three days anyway. (Besides, I kinda think Expires settings refer to the underlying filetype, which may be different from the visible extension, if any.)

:: detour to apache dot org ::

Oh, OK. The word “plus” really is optional; it just looks unnerving if you’re used to seeing it.

not2easy

5:27 pm on Sep 22, 2021 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



WP pages are HTML pages and use the <!DOCTYPE html> tag and </html> at the end, they are built using PHP templates but it is still a html document with no default .html or .php extension. If you view the source it is like any over-bloated html page.

lucy24

6:23 pm on Sep 22, 2021 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hm, interesting point. Does the server read the document’s dtd? I thought that was just for the browser’s use. I was thinking the server, when determining what headers to send out, goes by the underlying “real” file, which ultimately is index.php.

I think I can test this by direct experimentation; I just have to think of some benign response header to add. (I’ve got a clutch o pages that are html for browser purposes, but they’re “really” php via internal rewrites.)

robzilla

6:35 pm on Sep 22, 2021 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The content-type for pages that WordPress (or PHP, rather) puts out is still text/html, so technically what the browser downloads is an HTML page.

Setting ExpiresDefault "access 3 days" without a preceding ExpiresByType text/html means that all HTML pages (of the content-type text/html) can be cached client-side for up to 3 days. So someone who visits the homepage today, and then again in 2 days, may not see any updates you've made to the homepage in the meantime.

However, as I noted earlier it's possible that WordPress (or a plug-in you may have installed) sets its own Expiry headers, overruling Apache.