4

I wish to use Django Compressor to both minify and uglify my css and javascript. I have got it working such that I do an offline compression and all required javascript is compressed correctly.

The problem is that it does not uglify the code. My settings:

STATICFILES_FINDERS = (
    "django.contrib.staticfiles.finders.FileSystemFinder",
    "django.contrib.staticfiles.finders.AppDirectoriesFinder",
    "compressor.finders.CompressorFinder",
)
COMPRESS_ENABLED = True
COMPRESS_OFFLINE = True
COMPRESS_YUGLIFY_BINARY = "yuglify"
COMPRESS_YUGLIFY_JS_ARGUMENTS = "--mangle"

yuglify is on my path. I tried running it manually on a file to test, ie:yuglify file.js --mangle. It turns out that yuglify (which is a wrapper around uglify-js) does not support es6 and above.

I found another uglifier called terser which works perfectly from the terminal with es6 code. I therefore tried to replace the above settings with terser, ie:

COMPRESS_YUGLIFY_BINARY = "terser"
COMPRESS_YUGLIFY_JS_ARGUMENTS = "--mangle"

This also does not work in django-compressor. The result is that the files get minified but not uglified.

I would appreciate any suggestions on getting this working either with django-compressor or with an alternative package.

1
  • This is a waste of your time. Minified code won't make your page noticeably faster. Ugly code won't stop people from understanding it. Combining many tons of enormous files into one will save you bulky additional requests, but won't be as efficient as not having all that unnecessary weight in the first place. Commented Jun 6, 2019 at 15:37

1 Answer 1

4

If you look at the docs the default setting for COMPRESS_JS_FILTERS is

COMPRESS_JS_FILTERS = ['compressor.filters.jsmin.JSMinFilter']

So you need to add the 'compressor.filters.yuglify.YUglifyJSFilter' filter to it.

COMPRESS_JS_FILTERS = [
  'compressor.filters.jsmin.JSMinFilter',
  'compressor.filters.yuglify.YUglifyJSFilter',
]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.