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

Minify JS with source map #10

Open
almarklein opened this issue Mar 21, 2018 · 0 comments
Open

Minify JS with source map #10

almarklein opened this issue Mar 21, 2018 · 0 comments

Comments

@almarklein
Copy link
Member

@Korijn commented on Fri Sep 09 2016

To reduce JS size and increase page load times, you can use projects like UglifyJS to minify JS and let it output sourcemaps to continue to provide a pleasant debugging experience.

There are many ways to do it, but it can be very simple:

var result = UglifyJS.minify({"file1.js": "var a = function () {};"}, {
  outSourceMap: "out.js.map",
  fromString: true
});

// or

var result = UglifyJS.minify([ "file1.js", "file2.js", "file3.js" ], {
  outSourceMap: "out.js.map"
});

@almarklein commented on Sun Sep 11 2016

The problem with these is that they rely on nodejs, and I don't want to make that a dependency of Flexx. Ideally we'd use a pure-Python minifier (Flexx includes a very minimalist one that removes comments etc. but keeps the code readable (because it does not do sourcemaps). Another option might be to make nodejs an optional dependency.


@almarklein commented on Sun Sep 11 2016

Maybe there is stuff that we can use from https://github.com/django-compressor/django-compressor/tree/develop/compressor


@almarklein commented on Sun Sep 11 2016

Another option is to generate minified JS by the parser itself. It already has AST, so it should be well-capable to e.g. shorten variable names.


@Korijn commented on Sun Sep 11 2016

Did you see the section "Building for the browser"? http://lisperator.net/uglifyjs/ Maybe you can vendor it?


@almarklein commented on Sun Sep 11 2016

But then Flexx would first need to spin up a (local) browser send it the JS, get the JS back, and then spin up the actual browser with the app?


@Korijn commented on Sun Sep 11 2016

You raise a good point! I stand corrected. :)


@almarklein commented on Wed Nov 15 2017

Source maps explanation: https://www.schneems.com/2017/11/14/wtf-is-a-source-map/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant