aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2017-12-12 18:07:57 +0000
committerMatthew Somerville <matthew-github@dracos.co.uk>2017-12-12 21:04:05 +0000
commitd688eb43a99a3c7782343677cd7285f66cfb3c32 (patch)
treeb1779bdd27ce6416e3a75c26e1de6376cf711c02
parent823ed42d79ef5f20b937cc2ae2025dea0df7c610 (diff)
Only output JavaScript files once.
This allows us to e.g. more easily make sure jQuery is loaded where needed, even if it has already been loaded previously.
-rw-r--r--templates/web/base/common_footer_tags.html9
-rw-r--r--templates/web/base/common_scripts.html17
2 files changed, 9 insertions, 17 deletions
diff --git a/templates/web/base/common_footer_tags.html b/templates/web/base/common_footer_tags.html
index 915751802..a5be06df5 100644
--- a/templates/web/base/common_footer_tags.html
+++ b/templates/web/base/common_footer_tags.html
@@ -5,8 +5,13 @@
<!--[if lte IE 9]>
<script src="[% version('/vendor/history.polyfill.min.js') %]"></script>
<![endif]-->
-[% FOR script IN scripts ~%]
- [% script = script.0 ? script : [ script ] ~%]
+[%
+scripts_seen = {};
+FOR script IN scripts;
+ script = script.0 ? script : [ script ];
+ NEXT IF scripts_seen.${script.0};
+ scripts_seen.${script.0} = 1;
+ ~%]
<script src="[% script.0 %]"
[%~ FOR attr IN script.1 %] [% attr.key %]="[% attr.value %]"[% END ~%]
></script>
diff --git a/templates/web/base/common_scripts.html b/templates/web/base/common_scripts.html
index 4c8fcfe74..86e826b18 100644
--- a/templates/web/base/common_scripts.html
+++ b/templates/web/base/common_scripts.html
@@ -9,21 +9,16 @@ scripts.push(
start _ "/js/translation_strings." _ lang_code _ ".js?" _ Math.int( date.now / 3600 ),
);
-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');
- SET geolocation_loaded = 1;
scripts.push(
version('/js/geolocation.js'),
);
ELSE;
- SET jquery_loaded = 1;
scripts.push(
version('/js/validation_rules.js'),
version('/jslib/jquery-1.7.2.min.js'),
@@ -38,17 +33,9 @@ FOR script IN extra_js;
END;
IF c.user_exists AND (c.user.from_body OR c.user.is_superuser);
- IF NOT geolocation_loaded;
- scripts.push(
- version('/js/geolocation.js'),
- );
- END;
- IF NOT jquery_loaded;
- scripts.push(
- version('/jslib/jquery-1.7.2.min.js'),
- );
- END;
scripts.push(
+ version('/js/geolocation.js'),
+ version('/jslib/jquery-1.7.2.min.js'),
version('/cobrands/fixmystreet/staff.js')
);
IF c.user.has_body_permission_to('planned_reports');