Jay
Jay

Reputation: 31

Getting and Verifying Image Headers Expires

I am working on SEO and need to verify that Image Headers Expires is working. Both modules for expires and headers are installed and enabled.

Any ideas?

The .htaccess file has this in it

<IfModule mod_expires.c>
ExpiresByType application/javascript "access plus 2 days"
  ExpiresByType image/jpg "access plus 1 month"
  ExpiresByType image/jpeg "access plus 1 month"
  ExpiresByType image/gif "access plus 1 month"
  ExpiresByType image/png "access plus 1 month"
  ExpiresByType text/css "access plus 2 days"
</IfModule>

I have added this to both the wordpress/ directory and the wordpress/wp-content/ directory.

And yet the SEO tool is saying "Your server is not using expires header for your images."

to test using curl I have done

Date: Sun, 15 Jan 2023 04:31:01 GMT
Server: Apache
Location: https://www.jaycocioservices.com/about
Content-Type: text/html; charset=iso-8859-1

Upvotes: 3

Views: 370

Answers (1)

MrWhite
MrWhite

Reputation: 45988

You are missing the ExpiresActive directive to enable the generation of the relevant Expires and Cache-Control headers.

You don't need the <IfModule> wrapper - this is only going to mask the error if mod_expires is not installed.

You don't need the ExpiresByType image/jpg ... directive since the correct mime-type is image/jpeg, which you already have in the directive that follows.

You don't need to repeat these directives in both the /wordpress and /wordpress/wp-content directories. Placing these directives in the root .htaccess file should be sufficient and naturally applies to all subdirectories.

Also consider setting an ExpiresDefault directive for all other mime-types.

For example:

ExpiresActive On
ExpiresByType application/javascript "access plus 2 days"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType text/css "access plus 2 days"
ExpiresDefault "access plus 1 day"

to test using curl I have done

Date: Sun, 15 Jan 2023 04:31:01 GMT
Server: Apache
Location: https://www.jaycocioservices.com/about
Content-Type: text/html; charset=iso-8859-1

That looks like a redirect response (due to the presence of the Location header), which perhaps should not be cached anyway (or left to the browser default in the case of a 301). Make sure you are requesting the canonical URL to test.

This (/about text/html) is also for a request not covered by your existing mod_expires directives. You need to be requesting an image, CSS or JS file.

Upvotes: 2

Related Questions