From f9a1118b643611e87e339a8355a9b3b89a93f090 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 11 Aug 2008 05:29:41 +0000 Subject: [PATCH] FEATURE Added configurable Requirements::$write_js_to_body for performance improvements (turned off by default) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@60396 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/Requirements.php | 64 +++++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 21 deletions(-) diff --git a/core/Requirements.php b/core/Requirements.php index 829968d4a..9652f930a 100644 --- a/core/Requirements.php +++ b/core/Requirements.php @@ -81,6 +81,21 @@ class Requirements { */ public static $combine_js_with_jsmin = true; + /** + * Put all javascript includes at the bottom of the template + * before the closing tag instead of the tag. + * This means script downloads won't block other HTTP-requests, + * which can be a performance improvement. + * Caution: Doesn't work when modifying the DOM from those external + * scripts without listening to window.onload/document.ready + * (e.g. toplevel document.write() calls). + * + * @see http://developer.yahoo.com/performance/rules.html#js_bottom + * + * @var boolean + */ + public static $write_js_to_body = false; + /** * Register the given javascript file as required. * Filenames should be relative to the base, eg, 'sapphire/javascript/loader.js' @@ -277,7 +292,9 @@ class Requirements { $jsRequirements .= "\n"; } } - + + // add all inline javascript *after* including external files which + // they might rely on if(self::$customScript) { foreach(array_diff_key(self::$customScript,self::$blocked) as $script) { $jsRequirements .= "