Yahoo's Best Practices for Speeding Up Your Website states:
Put Scripts at the Bottom
That there are two types of scripts in my Django application:
Scripts to support UI controls are necessarily a part of the template for their supporting template tag to handle stuff like unique IDs and to keep dependent code together.
The problem is that if I follow Yahoo's advice and put the libraries (#1) at the bottom of the page, 100% of the scripts included inline (#2) will fail because the libraries haven't been loaded and parsed yet.
I can't extend a {% block %} element in my base template because anything I do within the context of the templatetag won't propagate outside it -- by design, to avoid variable name conflicts (according to Django's documentation).
Does anyone have any idea how I can defer JavaScript from my templatetags' templates to render at the bottom of my base template?
I usually have a base template setup like this.
<html>
<head>
{% block js-head %} Tags that need to go up top {% endblock js-head %}
</head>
<body>
{% block header %} Header {% endblock header %}
{% block body %} Body goes here {% endblock body %}
{% block footer %} Footer {% endblock footer %}
{% block js-foot %} All other javascript goes here {% endblock js-foot %}
</body>
</html>
Then I can extend this base template and only override the blocks that I care about. I put all javascript that doesn't have to be in the header in js-foot and because it is at the bottom of the template it will load last. If you have have to move where your javascript loads you just need to move the js-foot block around in the base template.
Nothing fancy but it works.