Why does django-pipeline's {% compressed_js … %} tag output each script separately?

Issue

I’ve configured pipeline as follows:

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'pipeline.finders.PipelineFinder',

)

# Static files storage
STATICFILES_STORAGE = 'pipeline.storage.PipelineStorage'

# Pipeline JS compressor
PIPELINE_JS_COMPRESSOR = 'pipeline.compressors.jsmin.JSMinCompressor'

PIPELINE_JS = {
    'website-main': {
        'source_filenames': (
          'shared/jquery/jquery-1.10.2.min.js',
          'shared/bootstrap/js/bootstrap.min.js',
          'shared/jquery/jquery.cookie.js',
        ),
        'output_filename': 'pipeline-compressed/website-main.js',
    }
}

When I use {% compressed_js 'website-main' %} in my template I get a script tag for each of the 3 files configured in PIPELINE_JS. Shouldn’t I see a single script tag with src="pipeline-compressed/website-main.js".

Solution

Set settings.DEBUG to False to use compressed files. Or set settings.PIPELINE_ENABLED to True.

According to Usage - django-pipeline, the setting checked is simply PIPELINE, but upon viewing the source of version 1.3.15, you’ll find that the setting is in fact PIPELINE_ENABLED:

The templatetags will either output the source filenames or the
compressed filenames, depending on the PIPELINE setting, if you do not
specify the PIPELINE setting, the source files will be used in
DEBUG-mode
, and compressed files in non-DEBUG-mode.

Answered By – falsetru

Answer Checked By – Candace Johnson (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.