]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/commitdiff
append javascript after CSS
authorAntoine Beaupré <anarcat@debian.org>
Mon, 6 Nov 2017 19:15:22 +0000 (14:15 -0500)
committerSimon McVittie <smcv@debian.org>
Sun, 3 Feb 2019 17:01:55 +0000 (17:01 +0000)
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* </body> 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
IkiWiki/Plugin/relativedate.pm
IkiWiki/Plugin/toggle.pm

index eb358be67bef0e8a87146846857d5bc24cfdc396..0093c655e222a2782582ff8d8128466188cf76f5 100644 (file)
@@ -60,9 +60,9 @@ sub pagetemplate (@) {
 sub format (@) {
         my %params=@_;
 
-       if (! ($params{content}=~s!^(<body[^>]*>)!$1.include_javascript($params{page})!em)) {
+       if (! ($params{content}=~s!^(\s*</body[^>]*>)!include_javascript($params{page}).$1!em)) {
                # no <body> tag, probably in preview mode
-               $params{content}=include_javascript(undef).$params{content};
+               $params{content}=$params{content}.include_javascript(undef);
        }
        return $params{content};
 }
index 4ae0be8615852db38222ebd892fd5c216bd5b4bf..083966ad2fc346c98fd24ed76af622471ff1d852 100644 (file)
@@ -26,9 +26,9 @@ sub getsetup () {
 sub format (@) {
         my %params=@_;
 
-       if (! ($params{content}=~s!^(<body[^>]*>)!$1.include_javascript($params{page})!em)) {
+       if (! ($params{content}=~s!^(\s*</body[^>]*>)!include_javascript($params{page}).$1!em)) {
                # no <body> tag, probably in preview mode
-               $params{content}=include_javascript(undef).$params{content};
+               $params{content}=$params{content}.include_javascript(undef);
        }
        return $params{content};
 }
index af4d2ba3a858774ac6b77be58479fb2a4a18d69c..eea6e8861f9dc3fdfc76ab7a4c95104971edcab8 100644 (file)
@@ -68,9 +68,9 @@ sub format (@) {
 
        if ($params{content}=~s!(<div class="toggleable(?:-open)?" id="[^"]+">\s*)</div>!$1!g) {
                $params{content}=~s/<div class="toggleableend">//g;
-               if (! ($params{content}=~s!^(<body[^>]*>)!$1.include_javascript($params{page})!em)) {
+               if (! ($params{content}=~s!^(\s*</body[^>]*>)!include_javascript($params{page}).$1!em)) {
                        # no <body> tag, probably in preview mode
-                       $params{content}=include_javascript(undef).$params{content};
+                       $params{content}=$params{content}.include_javascript(undef);
                }
        }
        return $params{content};