Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaScript compressor issue #1

Open
maxwelld90 opened this issue May 26, 2021 · 1 comment
Open

JavaScript compressor issue #1

maxwelld90 opened this issue May 26, 2021 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@maxwelld90
Copy link
Member

maxwelld90 commented May 26, 2021

Case in point: when we attempt to include react-plotly.js (which spits out huge output files!), and try and compress the JavaScript with compressor.filters.jsmin.JSMinFilter and compressor.filters.jsmin.CalmjsFilter, compression fails. When we remove compressor.filters.jsmin.CalmjsFilter, it compiles (allegedly having compressed things down), but does not work in the browser. The compression is not working correctly in some instances.

So is there a configuration issue with the compressor, or do we just need to find a new compressor?

Look for COMPRESS_JS_FILTERS in worker/worker/settings/base.py.

@maxwelld90 maxwelld90 self-assigned this May 26, 2021
@maxwelld90 maxwelld90 added the bug Something isn't working label May 26, 2021
@maxwelld90
Copy link
Member Author

maxwelld90 commented May 26, 2021

So it seems like the django-compressor code is messing everything up. There's a problem in there with larger modules (over 2-3MB in size), and it seems to spit out incorrect code when we try apply a filter to minify it.

The solution seems to be to completely skip the django-compressor COMPRESS_JS_FILTERS filters, and just minify it using the minify command.

  1. Ensure that minify is globally installed. Do this with npm install minify -g. We can add minify to line 29 of the Dockerfile for the worker.
  2. Remove all COMPRESS_JS_FILTERS from the base.py settings module for the worker.
  3. Alter the COMPRESS_PRECOMPILERS setting. Change the module tuple to the following.

('module', 'browserify {infile} -t babelify | minify --js > {outfile}'),

This should then mean that instead of passing the compression job to django-compressor, we do it directly by piping the output of babelify straight to minify, which then saves its output to the specified output file.

That should work! Tested on the fork by @hjpvandijk for his project. The 9MB JS file was reduced to 4MB. And it works fine in the browser. So I am pretty happy that this solution seems to work, unless we can find a further issue with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant