How to specify a short cache time in vBulletin 4 headinclude template

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • djbaxter
    Senior Member
    • Aug 2006
    • 1418
    • 4.2.5

    [Forum] How to specify a short cache time in vBulletin 4 headinclude template

    Using vBulletin 4.2.5.

    Problem: Sometimes a mobile browser on a slow data connection will not download all the CSS correctly, breaking the page displayed in the default vBulletin mobile style. Refreshing the page doesn't help, at least not for some time and I have no idea what the default expiration time is for mobile devices/browsers.

    I don't want to turn off caching completely.

    What I want to do is specify a short cache time, say 5 minutes.

    I'm having trouble finding the correct syntax for this.

    Is this correct?

    Code:
    <meta http-equiv="Cache-Control" content="must-revalidate, max-age=300" />
    or should it be

    Code:
    <meta http-equiv="Cache-Control: must-revalidate, max-age=300" />
    or is there a better way to do this.

    Additionally, can this be done only for mobile devices by inserting the meta tag just into the default mobile style?

    Psychlinks Web Services Affordable Web Design & Site Management
    Specializing in Small Businesses and vBulletin/Xenforo Forums
  • Wayne Luke
    vBulletin Technical Support Lead
    • Aug 2000
    • 74078

    #2
    There is no Cache-Control value for http-equiv supported by the standard. Due to this, not all browsers will support it. You should handle this in the web server (.htaccess) or via PHP (using the header() function).

    https://developer.mozilla.org/en-US/...L/Element/meta
    https://developer.mozilla.org/en-US/.../Cache-Control

    To do this in PHP, search the includes/init.php file for "mobile".

    You'll need something like:
    Code:
    <?php
      //set headers to NOT cache a page
      header("Cache-Control: no-cache, must-revalidate"); //HTTP 1.1
      header("Pragma: no-cache"); //HTTP 1.0
      header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
    
      //or, if you DO want a file to cache, use:
      header("Cache-Control: max-age=2592000"); //30days (60sec * 60min * 24hours * 30days)
    
    ?>
    Last edited by Wayne Luke; Thu 28 Jun '18, 12:12pm.
    Translations provided by Google.

    Wayne Luke
    The Rabid Badger - a vBulletin Cloud demonstration site.
    vBulletin 5 API

    Comment

    • Wayne Luke
      vBulletin Technical Support Lead
      • Aug 2000
      • 74078

      #3
      With vBulletin 5.X, we use this in the .htaccess file:

      Code:
      <IfModule mod_expires.c>
      	ExpiresActive On
      	ExpiresByType application/x-javascript A1209600
      	ExpiresByType text/javascript A1209600
      	ExpiresByType application/javascript A1209600
      	ExpiresByType text/css A31536000
      	ExpiresByType image/x-icon A2592000
      	ExpiresByType image/icon A2592000
      	ExpiresByType application/x-ico A2592000
      	ExpiresByType application/ico A2592000
      	ExpiresByType image/gif A2592000
      	ExpiresByType image/jpeg A1209600
      	ExpiresByType image/jpg A1209600
      	ExpiresByType image/png A1209600
      	ExpiresByType application/x-shockwave-flash A1209600
      	ExpiresByType font/ttf A2592000
      	ExpiresByType font/otf A2592000
      	ExpiresByType font/x-woff A2592000
      	ExpiresByType image/svg+xml A2592000
      	ExpiresByType font/truetype A2592000
      	ExpiresByType font/opentype A2592000
      	ExpiresByType application/x-font-woff A2592000
      	ExpiresByType application/vnd.ms-fontobject A2592000
      </IfModule>
      
      <IfModule mod_headers.c>
          Header set Connection keep-alive
      	<filesmatch "\.(ico|flv|gif|swf|eot|woff|otf|ttf|svg)$">
      		Header set Cache-Control "max-age=2592000, public"
      	</filesmatch>
      	<filesmatch "\.(jpg|jpeg|png)$">
      		Header set Cache-Control "max-age=1209600, public"
      	</filesmatch>
      	<filesmatch "\.(eot|woff|otf|ttf|svg)$">
      		Header set Cache-Control "max-age=2592000, public"
      	</filesmatch>
      	# css and js should use private for proxy caching https://developers.google.com/speed/docs/best-practices/caching#LeverageProxyCaching
      	<filesmatch "\.(css)$">
      		Header set Cache-Control "max-age=31536000, private"
      	</filesmatch>
      	<filesmatch "\.(js)$">
      		Header set Cache-Control "max-age=1209600, private"
      	</filesmatch>
      </IfModule>
      Translations provided by Google.

      Wayne Luke
      The Rabid Badger - a vBulletin Cloud demonstration site.
      vBulletin 5 API

      Comment

      • djbaxter
        Senior Member
        • Aug 2006
        • 1418
        • 4.2.5

        #4
        Thanks, Wayne.

        For an Apache server, what would the appropriate htaccess addition look like?

        You added your post above while I was posting this. Thanks, again.
        Psychlinks Web Services Affordable Web Design & Site Management
        Specializing in Small Businesses and vBulletin/Xenforo Forums

        Comment

        Related Topics

        Collapse

        Working...