Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Put <script> tags into the head, using defer
Browse files Browse the repository at this point in the history
Putting script tags at the end of the HTML element was done to avoid
blocking further HTML parsing and DOM loading – whenever a script tag
is encountered, a browser has to parse and interpret the JS inside of
it.  A disadvantage of this strategy is that the scripts will be fetched
only after parsing the HTML

Using `defer` while putting the scripts in the `head` solves both of
these problems.
lukasjuhrich committed Oct 9, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 6d11319 commit a0dd01f
Showing 7 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion sipa/templates/anonymous_contact.html
Original file line number Diff line number Diff line change
@@ -26,5 +26,5 @@
{% endblock %}

{% block custom_script %}
<script src="{{ url_for("static", filename="js/contact-hints.js") }}"></script>
<script defer src="{{ url_for("static", filename="js/contact-hints.js") }}"></script>
{% endblock %}
10 changes: 5 additions & 5 deletions sipa/templates/base.html
Original file line number Diff line number Diff line change
@@ -66,6 +66,11 @@
<script type="application/json" id="locale">
{{- get_locale() | string | tojson -}}
</script>
<script defer src="{{ url_for("static", filename="js/jquery-2.1.1.min.js") }}"></script>
<script defer src="{{ url_for("static", filename="js/bootstrap.bundle.min.js") }}"></script>
<script defer src="{{ url_for("static", filename="js/statuspage.js") }}"></script>
<script defer src="{{ url_for("static", filename="js/agdsn.js") }}"></script>
{% block custom_script %}{% endblock %}
</head>

<body class="js-toc-content">
@@ -435,10 +440,5 @@ <h2>
</div>
</footer>

<script src="{{ url_for("static", filename="js/jquery-2.1.1.min.js") }}"></script>
<script src="{{ url_for("static", filename="js/bootstrap.bundle.min.js") }}"></script>
<script src="{{ url_for("static", filename="js/statuspage.js") }}"></script>
<script src="{{ url_for("static", filename="js/agdsn.js") }}"></script>
{% block custom_script %}{% endblock %}
</body>
</html>
2 changes: 1 addition & 1 deletion sipa/templates/register/base.html
Original file line number Diff line number Diff line change
@@ -12,6 +12,6 @@ <h4>{{ title }}</h4>
{% endblock %}

{% block custom_script -%}
<script src="{{ url_for("static", filename="js/register_base.js") }}"></script>
<script defer src="{{ url_for("static", filename="js/register_base.js") }}"></script>
{% block register_custom_script %}{% endblock %}
{% endblock %}
2 changes: 1 addition & 1 deletion sipa/templates/register/identify.html
Original file line number Diff line number Diff line change
@@ -13,5 +13,5 @@
{% endblock %}

{%- block register_custom_script -%}
<script src="{{ url_for("static", filename="js/register_identify.js") }}"></script>
<script defer src="{{ url_for("static", filename="js/register_identify.js") }}"></script>
{%- endblock -%}
2 changes: 1 addition & 1 deletion sipa/templates/usersuite/contact.html
Original file line number Diff line number Diff line change
@@ -16,5 +16,5 @@
{% endblock %}

{% block custom_script %}
<script src="{{ url_for("static", filename="js/contact-hints.js") }}"></script>
<script defer src="{{ url_for("static", filename="js/contact-hints.js") }}"></script>
{% endblock %}
8 changes: 4 additions & 4 deletions sipa/templates/usersuite/index.html
Original file line number Diff line number Diff line change
@@ -22,8 +22,8 @@
{% endblock %}

{% block custom_script %}
<script src="{{ url_for("static", filename="js/tocbot.min.js") }}"></script>
<script src="{{ url_for("static", filename="js/usersuite_index.js") }}"></script>
<script src="{{ url_for("static", filename="js/svg.jquery.js") }}"></script>
<script src="{{ url_for("static", filename="js/pygal-tooltips.js") }}"></script>
<script defer src="{{ url_for("static", filename="js/tocbot.min.js") }}"></script>
<script defer src="{{ url_for("static", filename="js/usersuite_index.js") }}"></script>
<script defer src="{{ url_for("static", filename="js/svg.jquery.js") }}"></script>
<script defer src="{{ url_for("static", filename="js/pygal-tooltips.js") }}"></script>
{% endblock %}
4 changes: 2 additions & 2 deletions sipa/templates/usertraffic.html
Original file line number Diff line number Diff line change
@@ -14,6 +14,6 @@ <h2>{{ _("Nutzer-ID") }}</h2>
{% endblock %}

{% block custom_script %}
<script src="{{ url_for("static", filename="js/svg.jquery.js") }}"></script>
<script src="{{ url_for("static", filename="js/pygal-tooltips.js") }}"></script>
<script defer src="{{ url_for("static", filename="js/svg.jquery.js") }}"></script>
<script defer src="{{ url_for("static", filename="js/pygal-tooltips.js") }}"></script>
{% endblock %}

0 comments on commit a0dd01f

Please sign in to comment.