Cache-Control : no-cache

Discussion in 'Server Operation' started by francoisPE, Dec 10, 2021.

  1. francoisPE

    francoisPE Active Member HowtoForge Supporter

    Hello,

    I use ispconfig 3.2.7p1 with mutliple servers
    On my web server, I run Wordpress
    This wordpress send
    upload_2021-12-10_23-4-9.png

    That's understandable for me:
    My .htaccess contains
    Code:
    <IfModule mod_expires.c>
            ExpiresActive On
            ExpiresByType text/css "access 28 days"
            ExpiresByType text/html "access 28 days"
            ExpiresByType image/gif "access 28 days"
            ExpiresByType image/png "access 28 days"
            ExpiresByType image/jpg "access 28 days"
            ExpiresByType image/jpeg "access 28 days"
            ExpiresByType image/webp "access 28 days"
            ExpiresByType image/x-icon "access 28 days"
            ExpiresByType application/pdf "access 28 days"
            ExpiresByType application/javascript "access 28 days"
            ExpiresByType text/x-javascript "access 28 days"
            ExpiresByType application/x-shockwave-flash "access 28 days"
            ExpiresDefault "access 28 days"
    </IfModule>
    
    <IfModule mod_headers.c>
            <filesMatch "\.(ico|jpe?g|png|gif|webp|swf)$">
                    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>
    
    #Disable ETag
    FileETag None
    
    I succeed in removing "no-cache" from header with
    Code:
    <?php unset($header['Cache-Control']); ?>
    in header.php of my wordpress theme
    but it removes all Cache-Control settings what is not good regarding my .htaccess...

    I wonder if something inside Apache conf can force "no-cache"
    I google it but with low success !
    For info, I enable that modes
    Code:
      a2enmod suexec > /dev/null 2>&1
      a2enmod rewrite > /dev/null 2>&1
      a2enmod ssl > /dev/null 2>&1
      a2enmod actions > /dev/null 2>&1
      a2enmod include > /dev/null 2>&1
      a2enmod cgi > /dev/null 2>&1
      a2enmod dav_fs > /dev/null 2>&1
      a2enmod dav > /dev/null 2>&1
      a2enmod auth_digest > /dev/null 2>&1
      a2enmod fastcgi > /dev/null 2>&1
      a2enmod fcgid > /dev/null 2>&1
      a2enmod proxy_fcgi > /dev/null 2>&1
      a2enmod alias > /dev/null 2>&1
      a2enmod headers > /dev/null 2>&1
      a2enmod setenvif  > /dev/null 2>&1
      a2enmod env  > /dev/null 2>&1
      a2enmod dir  > /dev/null 2>&1
      a2enmod mime  > /dev/null 2>&1
      a2enmod proxy  > /dev/null 2>&1
      a2enmod proxy_http  > /dev/null 2>&1
      a2enmod proxy_wstunnel  > /dev/null 2>&1
      a2enmod proxy_html > /dev/null 2>&1
      a2enmod remoteip  > /dev/null 2>&1
    
    Can you help me to dig with some keyword to look at ?
     
    Last edited: Dec 10, 2021
  2. Jesse Norell

    Jesse Norell Well-Known Member Staff Member Howtoforge Staff

    I may not be exactly clear on what you're wanting, but instead of unsetting this completely, couldn't you just set it to the value you want?
     
  3. francoisPE

    francoisPE Active Member HowtoForge Supporter

    That's obvious...
    But I have difficulties to code that in PHP
    Code:
    <IfModule mod_expires.c>
           ExpiresActive On
           ExpiresByType text/css "access 28 days"
           ExpiresByType text/html "access 28 days"
           ExpiresByType image/gif "access 28 days"
           ExpiresByType image/png "access 28 days"
           ExpiresByType image/jpg "access 28 days"
           ExpiresByType image/jpeg "access 28 days"
           ExpiresByType image/webp "access 28 days"
           ExpiresByType image/x-icon "access 28 days"
           ExpiresByType application/pdf "access 28 days"
           ExpiresByType application/javascript "access 28 days"
           ExpiresByType text/x-javascript "access 28 days"
           ExpiresByType application/x-shockwave-flash "access 28 days"
           ExpiresDefault "access 28 days"
    </IfModule>
    
    <IfModule mod_headers.c>
           <filesMatch "\.(ico|jpe?g|png|gif|webp|swf)$">
                   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>
    
    #Disable ETag
    FileETag None
     
  4. francoisPE

    francoisPE Active Member HowtoForge Supporter

    I set cache control but it is only for html...
    So, I am back to my first idea : find out from where no-cache is coming !

    Is there a possibility to set in php.ini "Cache-control: no-cache" and if yes with which command. It try find on the internet that but I don't
     
  5. till

    till Super Moderator Staff Member ISPConfig Developer

    I guess it#s most likle yset by a wordpress plugin, you can find all code and plugins in Wordpress that set a cache control header with this command, run in the web folder of the site:

    grep -R Cache-Control * | grep /plugins/

    to get an idea of which plugins might set it.
     
  6. till

    till Super Moderator Staff Member ISPConfig Developer

    WP plugins that typically set such headers are SEO plugins, caching plugins but also security plugins like wordfence set it.
     
  7. francoisPE

    francoisPE Active Member HowtoForge Supporter

    I already did it and found 4 plugins
    Site health
    Matomo
    Webp express
    Wp optimize
    I try deactivate them with no success...
    I will try to remove them and even clean mariadb
     
  8. francoisPE

    francoisPE Active Member HowtoForge Supporter

    It's clear this is WP optimize !
    I don't understand, this plugin is setting that .htaccess
    Code:
    <IfModule mod_expires.c>
           ExpiresActive On
           ExpiresByType text/css "access 28 days"
           ExpiresByType text/html "access 28 days"
           ExpiresByType image/gif "access 28 days"
           ExpiresByType image/png "access 28 days"
           ExpiresByType image/jpg "access 28 days"
           ExpiresByType image/jpeg "access 28 days"
           ExpiresByType image/webp "access 28 days"
           ExpiresByType image/x-icon "access 28 days"
           ExpiresByType application/pdf "access 28 days"
           ExpiresByType application/javascript "access 28 days"
           ExpiresByType text/x-javascript "access 28 days"
           ExpiresByType application/x-shockwave-flash "access 28 days"
           ExpiresDefault "access 28 days"
    </IfModule>
    
    <IfModule mod_headers.c>
           <filesMatch "\.(ico|jpe?g|png|gif|webp|swf)$">
                   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>
    
    #Disable ETag
    FileETag None
     
    and at the same time it is sending : Cache-Control: no-cache !
    it looks like a bug, isn't it ?
     
  9. Jesse Norell

    Jesse Norell Well-Known Member Staff Member Howtoforge Staff

    No, having the two headers
    Code:
    Cache-Control: no-cache
    Cache-Control: private, must-revalidate
    
    Is the same as having a single
    Code:
    Cache-Control: no-cache, private, must-revalidate
     
  10. francoisPE

    francoisPE Active Member HowtoForge Supporter

    So I dig and find the line in wp-optimize cade that is sending "no-cache"
    I comment it. I have no more "no-cache" headers.
    In my .htaccess there is below code for Cache-control
    I use GTMetrix
    I understand why ttf files are not cached...
    But I don't understand why GTmetrix is telling that there is no TTL for css and not saying that for js ?
    For css, it is private, for js it is public.
    is there a difference between private and public regarding TTL setting...
    in both above header set directive there is no "max-age"...
     
  11. francoisPE

    francoisPE Active Member HowtoForge Supporter

    I finally solve my issue.
    I remove above snipset from .htaccess and decide to move on with a ROBUST software, I mean ISPConfig !
    I create snipset in ispc and I push them in concerned vhost !

    Thanks a lot for this amazing job you are doing with ispconfig !
    :):):)
     
    till likes this.

Share This Page