File: fix_javascript_load_ordering.mdwn

package info (click to toggle)
ikiwiki 3.20190228-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 20,904 kB
  • sloc: perl: 31,100; python: 428; sh: 185; makefile: 120
file content (22 lines) | stat: -rw-r--r-- 1,157 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[[!tag patch]]
[[!template  id=gitbranch branch=anarcat/reverse-js-includes author="[[users/anarcat]]"]]

As mentioned in [[todo/css_and_javascript_aggregation]] the current
ordering of Javascript files in [[plugins/toggle]],
[[plugins/relativedate]] and [[plugins/recentchangesdiff]] is
incorrect: Javascript files get loaded before the main content and may
even be loaded before the `<html>` tag for templates that indent the
`<body>` tag with whitespace.

According to the [best practices](https://developers.google.com/speed/docs/insights/mobile#PutStylesBeforeScripts) Javascript resources should be
presented to browsers after CSS, and "after the fold" (ATF) according
to the best practices. This allows the browser to download Javascript
files in parallel.

I have pushed a [simple patch](https://gitlab.com/anarcat/ikiwiki/commit/5caf6e1f87530dda74ec23eb1fa7120309607cc8) which fixes this issue by including
Javascript on the *closing* `</body>` tag instead of the *opening* tag.

It also improves the regex to tolerate spaces before the `</body>` tag,
as some templates have (proper) indentation for the tag.

> [[Applied|done]], thanks --[[smcv]]