Caching

Discussions and requests related to new CMSimple features, plugins, templates etc. and how to develop.
Please don't ask for support at this forums!
Post Reply
cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Caching

Post by cmb » Sat Jan 18, 2014 1:07 pm

Hello Community,

IMO we should try to improve the caching behavior of CMSimple_XH sites. On one hand several resources are often cached to aggressively (especially stylesheets), and on the other hand some resources might be cached to weak. The HTTP protocol has plenty of options to tune the desired caching for resources, but CMSimple_XH currently makes no explicit use of them and is instead relying on the webserver to handle this. However, I've seen some mostly old plugins, which sent some caching related headers, but IMO that's not the best idea, unless the plugin is responding directly (i.e. the plugins sends its own response, instead of passing through to CMSimple_XH's general handling).

Regarding the stylesheets: usually these are treated as being "fresh" by browsers, so not even a revalidation request is made to the server. This is a Good Thing, unless the stylesheet is modified, which goes unnoticed by a browser having the stylesheet already cached. One way to alleviate this would be to send an Expires or Cache-Control: max-age header, but IMO that doesn't solve the problem (and would require to configure the webserver appropriately resp. to deliver the stylesheet via PHP). Another more reasonable solution would be to add a "version number" (the timestamp of the last modifcation date seems to be appropriate) as query string to the stylesheet's URL. This would force the browser to fetch the new resource after it has changed. The tradeoff would be that the modifcation date has to be read on each request, but that shouldn't be much of a problem due to the reduced number of plugin stylesheets since XH 1.6.

A simple POC for the template's stylesheet:

Code: Select all

Index: tplfuncs.php
===================================================================
--- tplfuncs.php	(revision 3)
+++ tplfuncs.php	(working copy)
@@ -52,7 +52,7 @@
         ) . "\n"
         . tag(
             'link rel="stylesheet" href="' . $pth['file']['stylesheet']
-            . '" type="text/css"'
+            . '?' . filemtime($pth['file']['stylesheet']) . '" type="text/css"'
         ) . "\n"
         . $hjs;
 }
I'm not sure if we should tackle this topic for 1.6.x or delay it until 1.7/2.0.

BTW: While I'm mostly concerned with client side caching, even some server side caching might be considered.

Christoph
Christoph M. Becker – Plugins for CMSimple_XH

Post Reply