• I keep getting this warning in PageSpeed. I edited the .htaccess file with the following code (which doesn’t seem to work):

    # BEGIN WordPress
    # The directives (lines) between "BEGIN WordPress" and "END WordPress" are
    # dynamically generated, and should only be modified via WordPress filters.
    # Any changes to the directives between these markers will be overwritten.
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress
    # BEGIN LiteSpeed
    # The directives (lines) between <code>BEGIN LiteSpeed</code> and <code>END LiteSpeed</code> are
    # dynamically generated, and should only be modified via WordPress filters.
    # Any changes to the directives between these markers will be overwritten.
    <IfModule Litespeed>
    SetEnv noabort 1
    </IfModule>
    # END LiteSpeed
    
    # TN - START EXPIRES CACHE 
    ExpiresActive On
    ExpiresByType text/css "access 1 month"
    ExpiresByType text/html "access 1 month"
    ExpiresByType image/gif "access 1 year"
    ExpiresByType image/png "access 1 year"
    ExpiresByType image/jpg "access 1 year"
    ExpiresByType image/jpeg "access 1 year"
    ExpiresByType image/svg "access 1 year"
    ExpiresByType image/x-icon "access 1 year"
    ExpiresByType application/pdf "access 1 month"
    ExpiresByType application/xhtml-xml "access 1 month"
    ExpiresByType application/javascript "access 1 month" 
    ExpiresByType text/x-javascript "access 1 month"
    ExpiresByType application/x-shockwave-flash "access 1 month"
    ExpiresDefault "access 1 month"
    # TN - END EXPIRES CACHE
    
    # TN - BEGIN Cache-Control Headers
    <ifModule mod_headers.c>
    <filesMatch "\.(ico|jpeg|jpg|png|gif|swf|pdf|svg)$">
    Header set Cache-Control "public"
    </filesMatch>
    <filesMatch "\.(css)$">
    Header set Cache-Control "public"
    </filesMatch>
    <filesMatch "\.(js)$">
    Header set Cache-Control "private"
    </filesMatch>
    <filesMatch "\.(x?html?|php)$">
    Header set Cache-Control "private, must-revalidate"
    </filesMatch>
    </ifModule>
    # TN - END Cache-Control Headers
    
    # TN - BEGIN Turn ETags Off
    FileETag None
    # TN - END Turn ETags Off
Viewing 4 replies - 1 through 4 (of 4 total)
  • Hello @snippet24,

    Part of the code is missing the <IfModule mod_expires.c> ... </IfModule> to check whether the mod_expires.c is loaded by the Apache server process (httpd):

    # TN - START EXPIRES CACHE 
    <IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/css "access 1 month"
    ExpiresByType text/html "access 1 month"
    ExpiresByType image/gif "access 1 year"
    ExpiresByType image/png "access 1 year"
    ExpiresByType image/jpg "access 1 year"
    ExpiresByType image/jpeg "access 1 year"
    ExpiresByType image/svg "access 1 year"
    ExpiresByType image/x-icon "access 1 year"
    ExpiresByType application/pdf "access 1 month"
    ExpiresByType application/xhtml-xml "access 1 month"
    ExpiresByType application/javascript "access 1 month" 
    ExpiresByType text/x-javascript "access 1 month"
    ExpiresByType application/x-shockwave-flash "access 1 month"
    ExpiresDefault "access 1 month"
    </IfModule>
    # TN - END EXPIRES CACHE
    

    I recommend reading the following article that explains how to set up browser caching in WordPress without a plugin: https://www.wpfaster.org/code/how-to-leverage-browser-caching-in-wordpress-without-a-plugin

    Try these sites to test if your changes are working:

    Thread Starter snippet24

    (@snippet24)

    I added those if modules tags and still is not working :/

    # TN - START EXPIRES CACHE 
    <IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/css "access 1 month"
    ExpiresByType text/html "access 1 month"
    ExpiresByType image/gif "access 1 year"
    ExpiresByType image/png "access 1 year"
    ExpiresByType image/jpg "access 1 year"
    ExpiresByType image/jpeg "access 1 year"
    ExpiresByType image/svg "access 1 year"
    ExpiresByType image/x-icon "access 1 year"
    ExpiresByType application/pdf "access 1 month"
    ExpiresByType application/xhtml-xml "access 1 month"
    ExpiresByType application/javascript "access 1 month" 
    ExpiresByType text/x-javascript "access 1 month"
    ExpiresByType application/x-shockwave-flash "access 1 month"
    ExpiresDefault "access 1 month"
    </IfModule>
    # TN - END EXPIRES CACHE

    Full Code

    # BEGIN WordPress
    # The directives (lines) between "BEGIN WordPress" and "END WordPress" are
    # dynamically generated, and should only be modified via WordPress filters.
    # Any changes to the directives between these markers will be overwritten.
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress
    # BEGIN LiteSpeed
    # The directives (lines) between <code>BEGIN LiteSpeed</code> and <code>END LiteSpeed</code> are
    # dynamically generated, and should only be modified via WordPress filters.
    # Any changes to the directives between these markers will be overwritten.
    <IfModule Litespeed>
    SetEnv noabort 1
    </IfModule>
    # END LiteSpeed
    
    # TN - START EXPIRES CACHE 
    <IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/css "access 1 month"
    ExpiresByType text/html "access 1 month"
    ExpiresByType image/gif "access 1 year"
    ExpiresByType image/png "access 1 year"
    ExpiresByType image/jpg "access 1 year"
    ExpiresByType image/jpeg "access 1 year"
    ExpiresByType image/svg "access 1 year"
    ExpiresByType image/x-icon "access 1 year"
    ExpiresByType application/pdf "access 1 month"
    ExpiresByType application/xhtml-xml "access 1 month"
    ExpiresByType application/javascript "access 1 month" 
    ExpiresByType text/x-javascript "access 1 month"
    ExpiresByType application/x-shockwave-flash "access 1 month"
    ExpiresDefault "access 1 month"
    </IfModule>
    # TN - END EXPIRES CACHE
    
    # TN - BEGIN Cache-Control Headers
    <ifModule mod_headers.c>
    <filesMatch "\.(ico|jpeg|jpg|png|gif|swf|pdf|svg)$">
    Header set Cache-Control "public"
    </filesMatch>
    <filesMatch "\.(css)$">
    Header set Cache-Control "public"
    </filesMatch>
    <filesMatch "\.(js)$">
    Header set Cache-Control "private"
    </filesMatch>
    <filesMatch "\.(x?html?|php)$">
    Header set Cache-Control "private, must-revalidate"
    </filesMatch>
    </ifModule>
    # TN - END Cache-Control Headers
    
    # TN - BEGIN Turn ETags Off
    FileETag None
    # TN - END Turn ETags Off

    Maybe I should delete Autoptimize plugin’s cache?

    • This reply was modified 4 years, 1 month ago by snippet24.

    Hello @snippet24,

    Yes, delete the plugin’s cache and any other static file cache. And disable the plugin.

    Thread Starter snippet24

    (@snippet24)

    Did so and I’m afraid is still not fixed. I left the plugin disabled for now.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to fix Serve static assets with an efficient cache policy without plugins’ is closed to new replies.