From fcc2fc8516e3eace578f947445bba0335756cc16 Mon Sep 17 00:00:00 2001 From: Heros Date: Tue, 28 Feb 2017 13:07:59 +0100 Subject: [PATCH] Deferred script loading, scripts from AddOns Add the 'defer' attribute to external script requests. Warning 1: This is only OK when the whole page is using 'defer', otherwise script execution order might be wrong! Warning 2: IE<=9 does not support 'defer' properly! Deferred script loading * Added 'defer' to jsfile loading * Moved inline js loading down for not interrupting deferred css and js loading --- core/templates/layout.base.php | 8 ++++---- core/templates/layout.guest.php | 8 ++++---- core/templates/layout.user.php | 8 ++++---- lib/private/legacy/template.php | 3 +++ 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/core/templates/layout.base.php b/core/templates/layout.base.php index d6d70f31362a2..9019f3782dbfe 100644 --- a/core/templates/layout.base.php +++ b/core/templates/layout.base.php @@ -18,15 +18,15 @@ + + + + - - - - diff --git a/core/templates/layout.guest.php b/core/templates/layout.guest.php index 1692e4268d474..d3327529eb5d9 100644 --- a/core/templates/layout.guest.php +++ b/core/templates/layout.guest.php @@ -19,15 +19,15 @@ + + + + - - - - diff --git a/core/templates/layout.user.php b/core/templates/layout.user.php index e9a9b042e07f0..ab065311f0105 100644 --- a/core/templates/layout.user.php +++ b/core/templates/layout.user.php @@ -26,15 +26,15 @@ + + + + - - - - diff --git a/lib/private/legacy/template.php b/lib/private/legacy/template.php index 09e3d130f4961..0a29ae9fa009e 100644 --- a/lib/private/legacy/template.php +++ b/lib/private/legacy/template.php @@ -233,6 +233,9 @@ public function fetchPage($additionalParams = null) { $headers = ''; foreach(OC_Util::$headers as $header) { $headers .= '<'.\OCP\Util::sanitizeHTML($header['tag']); + if ( strcasecmp($header['tag'], 'script') == 0 and in_array('src', array_map('strtolower', array_keys($header['attributes']))) ) { + $headers .= ' defer'; + } foreach($header['attributes'] as $name=>$value) { $headers .= ' '.\OCP\Util::sanitizeHTML($name).'="'.\OCP\Util::sanitizeHTML($value).'"'; }