Issue #19 open

.js can't be included at the bottom of <body>

Antti Kaihola
created an issue

Web developers may want, for performance reasons, to load {{{.js}}} files only just before the closing {{{</body>}}} tag. This isn't possible when using django-autocomplete since the call to {{{new autocomplete()}}} appears together with each field in the HTML.

I've experimented with replacing the {{{new autocomplete()}}} calls with building up a global array of auto-complete field data. The array is parsed and {{{new autocomplete()}}} called for each item when {{{jquery.autocomplete.js}}} is finally loaded and initialized.

Comments (5)

  1. Germano Gabbianelli repo owner

    Maybe you could do something like this.

    Put the following script in the head of your document, that changes the behavior of the django.autocomplete function to store all the ids/options into an object.

    var django = {};
    django.autocomplete_widgets = {};
    django.autocomplete = function(id, options) {
        django.autcomplete_widgets[id] = options;

    then load the scripts at the end of the page with {{ }} and finally call djangoautocomplete for each input.

    django.jQuery(function() {
        for (var id in django.autocomplete_widgets) {
            django.autocomplete(id, django.autocomplete_widgets[id]);

    I've not tested the code ...

  2. Log in to comment