Purge browser cache using a timestamp variable when switching templates.

This should hopefully fix Ian and my problems.
This commit is contained in:
Garvin Hicking 2013-01-28 09:35:34 +01:00
parent 18dcec7bdd
commit 71ee300143
4 changed files with 30 additions and 2 deletions

View File

@ -3,8 +3,12 @@
Version 2.0 ()
------------------------------------------------------------------------
* When switching templates, both the backend and the frontend
will remember the timestamp of the last template change,
to make sure that the browser will not cache a mismatching CSS.
* Use Smarty for backend display output
Version 1.7 ()
------------------------------------------------------------------------

View File

@ -65,6 +65,7 @@ if ($serendipity['GET']['adminAction'] == 'install' ) {
serendipity_set_config_var('template', htmlspecialchars($serendipity['GET']['theme']));
serendipity_set_config_var('template_engine', isset($themeInfo['engine']) ? $themeInfo['engine'] : 'default');
serendipity_set_config_var('last_template_change', time());
$data["adminAction"] = "install";
$data["install_template"] = htmlspecialchars($serendipity['GET']['theme']);

View File

@ -967,6 +967,14 @@ function serendipity_smarty_init($vars = array()) {
if (!isset($serendipity['smarty_vars']['head_link_stylesheet'])) {
$serendipity['smarty_vars']['head_link_stylesheet'] = serendipity_rewriteURL('serendipity.css');
// When templates are switched, append a specific version string to make sure the browser does not cache the CSS
if (strstr($serendipity['smarty_vars']['head_link_stylesheet'], '?')) {
$serendipity['smarty_vars']['head_link_stylesheet'] .= '&v=' . $serendipity['last_template_change'];
} else {
$serendipity['smarty_vars']['head_link_stylesheet'] .= '?v=' . $serendipity['last_template_change'];
}
}
$serendipity['smarty']->assign(

View File

@ -14,9 +14,24 @@ if (IS_installed === false) {
require(S9Y_INCLUDE_PATH . 'include/functions_permalinks.inc.php');
require(S9Y_INCLUDE_PATH . 'include/functions_installer.inc.php');
require(S9Y_INCLUDE_PATH . 'include/functions_config.inc.php');
$css_file = 'serendipity.css.php?serendipity[css_mode]=serendipity_admin.css';
$css_file = 'serendipity.css.php?serendipity[css_mode]=serendipity_admin.css&v=' . time();
} else {
$css_file = serendipity_rewriteURL('serendipity_admin.css');
// This is a bit of an ugly hack, but when switching templates, the HTML head is already emitted,
// so we need a way to actually enforce switching/updating the CSS. So we need to do it at
// this place.
if ($serendipity['GET']['adminAction'] == 'install' && $serendipity['GET']['adminModule'] == 'templates') {
$serendipity['last_template_change'] = time();
}
// When templates are switched, append a specific version string to make sure the browser does not cache the CSS
if (strstr($css_file, '?')) {
$css_file .= '&v=' . $serendipity['last_template_change'];
} else {
$css_file .= '?v=' . $serendipity['last_template_change'];
}
if (defined('IS_up2date') && IS_up2date === true) {
serendipity_plugin_api::hook_event('backend_configure', $serendipity);
}