From: Antoine Beaupré Date: Mon, 6 Nov 2017 19:15:22 +0000 (-0500) Subject: append javascript after CSS X-Git-Tag: 3.20190207~7 X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/commitdiff_plain/d16e34c736676256b7cd3ea12797313dc1332fc3 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. --- 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};