From 6619f42eb475ad91a0b73d1aa6268ff41c6129a2 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Fri, 1 Jul 2011 16:49:28 +0200 Subject: Refactor CSS and JS caching * Increase HTTP cache time since the resources are timestamped on request anyway * Check userscript.js only once for JS cache validation * Use cache class --- lib/exe/js.php | 67 ++++++++-------------------------------------------------- 1 file changed, 9 insertions(+), 58 deletions(-) (limited to 'lib/exe/js.php') diff --git a/lib/exe/js.php b/lib/exe/js.php index 28894ffc6..0688825c6 100644 --- a/lib/exe/js.php +++ b/lib/exe/js.php @@ -32,7 +32,8 @@ function js_out(){ global $config_cascade; // The generated script depends on some dynamic options - $cache = getCacheName('scripts'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'],'.js'); + $cache = new cache('scripts'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'], + '.js'); // load minified version for some files $min = $conf['compress'] ? '.min' : ''; @@ -70,25 +71,13 @@ function js_out(){ $files[] = $config_cascade['userscript']['default']; } + $cache_files = array_merge($files, getConfigFiles('main')); + $cache_files[] = __FILE__; + // check cache age & handle conditional request - header('Cache-Control: public, max-age=3600'); - header('Pragma: public'); - if(js_cacheok($cache,$files)){ - http_conditionalRequest(filemtime($cache)); - if($conf['allowdebug']) header("X-CacheUsed: $cache"); - - // finally send output - if ($conf['gzip_output'] && http_gzip_valid($cache)) { - header('Vary: Accept-Encoding'); - header('Content-Encoding: gzip'); - readfile($cache.".gz"); - } else { - if (!http_sendfile($cache)) readfile($cache); - } - return; - } else { - http_conditionalRequest(time()); - } + // This may exit if a cache can be used + http_cached($cache->cache, + $cache->useCache(array('files' => $cache_files))); // start output buffering and build the script ob_start(); @@ -137,18 +126,7 @@ function js_out(){ $js .= "\n"; // https://bugzilla.mozilla.org/show_bug.cgi?id=316033 - // save cache file - io_saveFile($cache,$js); - if(function_exists('gzopen')) io_saveFile("$cache.gz",$js); - - // finally send output - if ($conf['gzip_output']) { - header('Vary: Accept-Encoding'); - header('Content-Encoding: gzip'); - print gzencode($js,9,FORCE_GZIP); - } else { - print $js; - } + http_cached_finish($cache->cache, $js); } /** @@ -183,33 +161,6 @@ function js_load($file){ echo "$data\n"; } -/** - * Checks if a JavaScript Cache file still is valid - * - * @author Andreas Gohr - */ -function js_cacheok($cache,$files){ - if(isset($_REQUEST['purge'])) return false; //support purge request - - $ctime = @filemtime($cache); - if(!$ctime) return false; //There is no cache - - global $config_cascade; - - // some additional files to check - $files = array_merge($files, getConfigFiles('main')); - $files[] = $config_cascade['userscript']['default']; - $files[] = __FILE__; - - // now walk the files - foreach($files as $file){ - if(@filemtime($file) > $ctime){ - return false; - } - } - return true; -} - /** * Returns a list of possible Plugin Scripts (no existance check here) * -- cgit v1.2.3 From ddf8a04fe3281e871c5311235b08185a5ceab797 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 8 Jul 2011 12:20:02 +0200 Subject: moved some editor functions to a new dw_editor object There are probably more functions that should go in here --- lib/exe/js.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/exe/js.php') diff --git a/lib/exe/js.php b/lib/exe/js.php index 0688825c6..720e34577 100644 --- a/lib/exe/js.php +++ b/lib/exe/js.php @@ -55,6 +55,7 @@ function js_out(){ DOKU_INC.'lib/scripts/textselection.js', DOKU_INC.'lib/scripts/toolbar.js', DOKU_INC.'lib/scripts/edit.js', + DOKU_INC.'lib/scripts/editor.js', DOKU_INC.'lib/scripts/locktimer.js', DOKU_INC.'lib/scripts/linkwiz.js', DOKU_INC.'lib/scripts/media.js', @@ -107,7 +108,6 @@ function js_out(){ // init stuff js_runonstart("addEvent(document,'click',closePopups)"); js_runonstart('addTocToggle()'); - js_runonstart("initSizeCtl('size__ctl','wiki__text')"); js_runonstart("initToolbar('tool__bar','wiki__text',toolbar)"); if($conf['locktime'] != 0){ js_runonstart("locktimer.init(".($conf['locktime'] - 60).",'".js_escape($lang['willexpire'])."',".$conf['usedraft'].", 'wiki__text')"); -- cgit v1.2.3 From 32cb905a0339607a7acfef6488bec0015bae6b8b Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 8 Jul 2011 13:04:59 +0200 Subject: moved the TOC toggling to dw_behaviour --- lib/exe/js.php | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/exe/js.php') diff --git a/lib/exe/js.php b/lib/exe/js.php index 720e34577..308c1b534 100644 --- a/lib/exe/js.php +++ b/lib/exe/js.php @@ -107,7 +107,6 @@ function js_out(){ // init stuff js_runonstart("addEvent(document,'click',closePopups)"); - js_runonstart('addTocToggle()'); js_runonstart("initToolbar('tool__bar','wiki__text',toolbar)"); if($conf['locktime'] != 0){ js_runonstart("locktimer.init(".($conf['locktime'] - 60).",'".js_escape($lang['willexpire'])."',".$conf['usedraft'].", 'wiki__text')"); -- cgit v1.2.3 From d10c9a7424d1ef0aace2fd34e1008196d111a88c Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Thu, 7 Jul 2011 16:08:05 +0200 Subject: Rewrite mediamanager JavaScript Make it faster, prettier, less wrong, add UI effects, use jQuery UI Dialog, Abstract tree view stuff away into jQuery.dw_tree --- lib/exe/js.php | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/exe/js.php') diff --git a/lib/exe/js.php b/lib/exe/js.php index 308c1b534..44ab2d5ca 100644 --- a/lib/exe/js.php +++ b/lib/exe/js.php @@ -50,6 +50,7 @@ function js_out(){ DOKU_INC.'lib/scripts/script.js', DOKU_INC.'lib/scripts/tw-sack.js', DOKU_INC.'lib/scripts/qsearch.js', + DOKU_INC.'lib/scripts/tree.js', DOKU_INC.'lib/scripts/index.js', DOKU_INC.'lib/scripts/drag.js', DOKU_INC.'lib/scripts/textselection.js', -- cgit v1.2.3