diff options
author | Cash Costello <cash.costello@gmail.com> | 2013-04-13 06:25:39 -0700 |
---|---|---|
committer | Cash Costello <cash.costello@gmail.com> | 2013-04-13 06:25:39 -0700 |
commit | d679c1578633a15c91561b1a23c8eee281823a75 (patch) | |
tree | 48b9ae6058c61e216af604117aa80db7c28ba6cb | |
parent | 46f4c707dc302979bf142c41b65546966287aa84 (diff) | |
parent | 31f5e27f60f3d9e5fcb3b6b9ab01b9d64a244b87 (diff) | |
download | elgg-d679c1578633a15c91561b1a23c8eee281823a75.tar.gz elgg-d679c1578633a15c91561b1a23c8eee281823a75.tar.bz2 |
Merge pull request #5308 from mrclay/3754-18
Fixes #3754: Language JS views send cache headers and support conditional get
-rw-r--r-- | js/lib/languages.js | 3 | ||||
-rw-r--r-- | views/default/js/languages.php | 24 |
2 files changed, 24 insertions, 3 deletions
diff --git a/js/lib/languages.js b/js/lib/languages.js index 44ea56d2b..d218cbc4f 100644 --- a/js/lib/languages.js +++ b/js/lib/languages.js @@ -30,6 +30,9 @@ elgg.reload_all_translations = function(language) { var url, options; url = 'ajax/view/js/languages'; options = {data: {language: lang}}; + if (elgg.config.simplecache_enabled) { + options.data.lc = elgg.config.lastcache; + } options['success'] = function(json) { elgg.add_translation(lang, json); diff --git a/views/default/js/languages.php b/views/default/js/languages.php index c51d7bcb2..fcf903d4b 100644 --- a/views/default/js/languages.php +++ b/views/default/js/languages.php @@ -1,15 +1,33 @@ <?php /** * @uses $vars['language'] + * @uses $vars['lc'] if present, client will be sent long expires headers */ -global $CONFIG; $language = $vars['language']; +$lastcache = elgg_extract('lc', $vars, 0); -$translations = $CONFIG->translations['en']; +// @todo add server-side caching +if ($lastcache) { + // we're relying on lastcache changes to predict language changes + $etag = '"' . md5("$language|$lastcache") . '"'; + + header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', strtotime("+6 months")), true); + header("Pragma: public", true); + header("Cache-Control: public", true); + header("ETag: $etag"); + + if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && trim($_SERVER['HTTP_IF_NONE_MATCH']) === $etag) { + header("HTTP/1.1 304 Not Modified"); + exit; + } +} + +$all_translations = elgg_get_config('translations'); +$translations = $all_translations['en']; if ($language != 'en') { - $translations = array_merge($translations, $CONFIG->translations[$language]); + $translations = array_merge($translations, $all_translations[$language]); } echo json_encode($translations);
\ No newline at end of file |