From 607c9676f52a3554747c51c8b9c243315ddbc99d Mon Sep 17 00:00:00 2001 From: Andrew-Chen-Wang Date: Wed, 4 Nov 2020 11:54:21 -0500 Subject: [PATCH 1/2] Use defer for script tags (Fix #2922) * This way, scripts from external URLs are loaded asynchronously. By putting it at the top of the file, the browser parses it first, downloads it while continuing to parse the HTML, and then executes on parsing finish * Additionally, developers will not need to use $(window).ready() or the like in their files anymore. * Added inline_javascript tag in case anyone wants to use the bottom of the HTML page to execute some Javascript. Using defer here has no effect as inline scripts defer by default Signed-off-by: Andrew-Chen-Wang --- .../templates/account/email.html | 2 +- .../templates/base.html | 51 ++++++++++--------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/templates/account/email.html b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/templates/account/email.html index 78d997365..8b4669bb6 100644 --- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/templates/account/email.html +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/templates/account/email.html @@ -59,7 +59,7 @@ {% endblock %} -{% block javascript %} +{% block inline_javascript %} {{ block.super }} + {% endraw %}{% if cookiecutter.use_compressor == "y" %}{% raw %}{% endcompress %}{% endraw %}{% endif %}{% raw %} + {% endraw %}{% else %}{% raw %} + + + + + + + {% endraw %}{% endif %}{% raw %} + + + {% endraw %}{% if cookiecutter.use_compressor == "y" %}{% raw %}{% compress js %}{% endraw %}{% endif %}{% raw %} + + {% endraw %}{% if cookiecutter.use_compressor == "y" %}{% raw %}{% endcompress %}{% endraw %}{% endif %}{% raw %} + + {% endblock javascript %} @@ -92,30 +116,9 @@ {% block modal %}{% endblock modal %} - - - {% block javascript %} - {% endraw %}{% if cookiecutter.custom_bootstrap_compilation == "y" and cookiecutter.js_task_runner == "Gulp" %}{% raw %} - - {% endraw %}{% if cookiecutter.use_compressor == "y" %}{% raw %}{% compress js %}{% endraw %}{% endif %}{% raw %} - - {% endraw %}{% if cookiecutter.use_compressor == "y" %}{% raw %}{% endcompress %}{% endraw %}{% endif %}{% raw %} - {% endraw %}{% else %}{% raw %} - - - - - - - {% endraw %}{% endif %}{% raw %} - - - {% endraw %}{% if cookiecutter.use_compressor == "y" %}{% raw %}{% compress js %}{% endraw %}{% endif %}{% raw %} - - {% endraw %}{% if cookiecutter.use_compressor == "y" %}{% raw %}{% endcompress %}{% endraw %}{% endif %}{% raw %} - - {% endblock javascript %} + {% block inline_javascript %} + {# Script tags with only code, no src (defer by default) #} + {% endblock inline_javascript %} {% endraw %} From 1fa5d798134fcb6a230f0a2cb8bb8f4e6517925b Mon Sep 17 00:00:00 2001 From: Andrew Chen Wang <60190294+Andrew-Chen-Wang@users.noreply.github.com> Date: Sat, 14 Nov 2020 10:27:14 -0500 Subject: [PATCH 2/2] Add "defer" for inline Javascript * Also utilize ECMAScript 6, 2015 syntax --- .../templates/account/email.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/templates/account/email.html b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/templates/account/email.html index 8b4669bb6..2b7e12789 100644 --- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/templates/account/email.html +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/templates/account/email.html @@ -62,17 +62,17 @@ {% block inline_javascript %} {{ block.super }}