From d16e34c736676256b7cd3ea12797313dc1332fc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Mon, 6 Nov 2017 14:15:22 -0500 Subject: append javascript after CSS Javascript resources should be presented to browsers after CSS, and "after the fold" (ATF) according to the best practices: https://developers.google.com/speed/docs/insights/mobile#PutStylesBeforeScripts This change allows the browser to download Javascript files in parallel, by including Javascript on the *closing* tag instead of the opening tag. We also improve the regex to tolerate spaces before the body tag, as some templates have (proper) indentation for the tag. --- IkiWiki/Plugin/recentchangesdiff.pm | 4 ++-- IkiWiki/Plugin/relativedate.pm | 4 ++-- IkiWiki/Plugin/toggle.pm | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/recentchangesdiff.pm b/IkiWiki/Plugin/recentchangesdiff.pm index eb358be67..0093c655e 100644 --- a/IkiWiki/Plugin/recentchangesdiff.pm +++ b/IkiWiki/Plugin/recentchangesdiff.pm @@ -60,9 +60,9 @@ sub pagetemplate (@) { sub format (@) { my %params=@_; - if (! ($params{content}=~s!^(]*>)!$1.include_javascript($params{page})!em)) { + if (! ($params{content}=~s!^(\s*]*>)!include_javascript($params{page}).$1!em)) { # no tag, probably in preview mode - $params{content}=include_javascript(undef).$params{content}; + $params{content}=$params{content}.include_javascript(undef); } return $params{content}; } diff --git a/IkiWiki/Plugin/relativedate.pm b/IkiWiki/Plugin/relativedate.pm index 4ae0be861..083966ad2 100644 --- a/IkiWiki/Plugin/relativedate.pm +++ b/IkiWiki/Plugin/relativedate.pm @@ -26,9 +26,9 @@ sub getsetup () { sub format (@) { my %params=@_; - if (! ($params{content}=~s!^(]*>)!$1.include_javascript($params{page})!em)) { + if (! ($params{content}=~s!^(\s*]*>)!include_javascript($params{page}).$1!em)) { # no tag, probably in preview mode - $params{content}=include_javascript(undef).$params{content}; + $params{content}=$params{content}.include_javascript(undef); } return $params{content}; } diff --git a/IkiWiki/Plugin/toggle.pm b/IkiWiki/Plugin/toggle.pm index af4d2ba3a..eea6e8861 100644 --- a/IkiWiki/Plugin/toggle.pm +++ b/IkiWiki/Plugin/toggle.pm @@ -68,9 +68,9 @@ sub format (@) { if ($params{content}=~s!(
\s*)
!$1!g) { $params{content}=~s/
//g; - if (! ($params{content}=~s!^(]*>)!$1.include_javascript($params{page})!em)) { + if (! ($params{content}=~s!^(\s*]*>)!include_javascript($params{page}).$1!em)) { # no tag, probably in preview mode - $params{content}=include_javascript(undef).$params{content}; + $params{content}=$params{content}.include_javascript(undef); } } return $params{content}; -- cgit v1.2.3