diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2017-11-14 16:23:11 +0000 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2017-11-15 16:02:26 +0000 |
commit | f59e12ee3fa9c65f178a300954586f6ac91bba79 (patch) | |
tree | e28721f5b356f5b916e59811a192cc96cc32ac4c /templates/web/base | |
parent | 865df7790d20ffbeacd8dd10316f4a7f733dcb1d (diff) |
Have front page load minimal JS necessary.
By creating a small file with only what is needed (focus, js flagging),
we can drop loading jQuery and all the application JavaScript on the
front page, prefetching them instead.
Diffstat (limited to 'templates/web/base')
-rw-r--r-- | templates/web/base/common_header_tags.html | 5 | ||||
-rw-r--r-- | templates/web/base/common_scripts.html | 14 |
2 files changed, 16 insertions, 3 deletions
diff --git a/templates/web/base/common_header_tags.html b/templates/web/base/common_header_tags.html index 1dad1cfa0..f65f1e336 100644 --- a/templates/web/base/common_header_tags.html +++ b/templates/web/base/common_header_tags.html @@ -36,7 +36,12 @@ [% IF bodyclass.match('frontpage') %] <link rel="prefetch" href="[% version('/js/validation_rules.js') %]"> + [%~ IF NOT c.user_exists OR NOT (c.user.from_body OR c.user.is_superuser) %] + <link rel="prefetch" href="[% version('/jslib/jquery-1.7.2.min.js') %]"> + [%~ END %] + <link rel="prefetch" href="[% version('/js/jquery.multi-select.js') %]"> <link rel="prefetch" href="[% version('/vendor/jquery.validate.min.js') %]"> + <link rel="prefetch" href="[% version('/cobrands/fixmystreet/fixmystreet.js') %]"> [% END %] [% IF NOT bodyclass.match('mappage') %] [% FOR script IN map_js %] diff --git a/templates/web/base/common_scripts.html b/templates/web/base/common_scripts.html index b04404f06..c6225e8fa 100644 --- a/templates/web/base/common_scripts.html +++ b/templates/web/base/common_scripts.html @@ -7,15 +7,14 @@ scripts = []; scripts.push( start _ "/js/translation_strings." _ lang_code _ ".js?" _ Math.int( date.now / 3600 ), - version('/jslib/jquery-1.7.2.min.js'), - version('/js/jquery.multi-select.js'), - version('/cobrands/fixmystreet/fixmystreet.js'), ); +SET jquery_loaded = 0; SET geolocation_loaded = 0; IF bodyclass.match('frontpage'); SET geolocation_loaded = 1; scripts.push( + version('/js/front.js'), version('/js/geolocation.js'), ); ELSIF bodyclass.match('alertpage'); @@ -24,9 +23,13 @@ ELSIF bodyclass.match('alertpage'); version('/js/geolocation.js'), ); ELSE; + SET jquery_loaded = 1; scripts.push( version('/js/validation_rules.js'), + version('/jslib/jquery-1.7.2.min.js'), + version('/js/jquery.multi-select.js'), version('/vendor/jquery.validate.min.js'), + version('/cobrands/fixmystreet/fixmystreet.js'), ); END; @@ -40,6 +43,11 @@ IF c.user_exists AND (c.user.from_body OR c.user.is_superuser); version('/js/geolocation.js'), ); END; + IF NOT jquery_loaded; + scripts.push( + version('/jslib/jquery-1.7.2.min.js'), + ); + END; scripts.push( version('/cobrands/fixmystreet/staff.js') ); |