-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Remove Closure Compiler aggressive variable mangling #1586
Comments
Don't forget that uglifyjs has other options, too. By default it doesn't do any aggressive mangling, so, we could enable more aggressive mangling. I believe it will by default not mangle function names on prototypes or stuff that it thinks should be available publicly, so, an externs file probably won't be needed. This is closely tied with #1013 where users would include vjs themselves and have vjs minified along with their js. With regard to filesize, we should also consider the size after gzip. However, we should also consider the headaches and bugs and wasted hours that the advanced optimization of GCC have caused developers using videojs during development. |
Gzip is a good point. I have seen less of a difference after gzipping in the past, so I'll test that again. Re: Uglify, I used all the additional settings in this blog post. |
Looks reasonable. We can probably play around with it for some time to tweak it for smallest size while not requiring an externs file or something. |
It would seem like the underscore prefix for private vars is more common than the suffix. As part of this process should we switch from While it shouldn't be a breaking change, it would change a lot of variable names. At the same time if we think it's something we'd ever do, it'd be better to do it now rather than later. |
I would be for changing to a prefix. Besides being more common, as you mention, I find it more aesthetically pleasing. |
When looking at a list of object properties, underscore-first would group private vars together, rather than next to their setter/getter function. Not sure which of those I like better, but it's a data point. |
The videojs_rails gem used to use the dev version of video JS in 4.6.1, 4.6.4 changed to use the minified version. We’re having problems running the minified version on FutureLearn.com against our plugins, particularly one that adds a button to the control bar. It seems that it’s an ongoing problem in the video js project that the minified version doesn’t correctly expose all the expected APIs that plugins need and use[1][2]. We haven’t been able to confirm what API method is unavailable- it looks to be something around overriding behaviour of elements. There were no errors in the console so it was hard to pin down what is wrong. We’ve tried other plugins that add buttons that are listed on the video js project (such as the loop button[3]) and have had the same problem. We feel that using the dev version is the easiest way to work around this problem until video js improves their minification process[1] and we don’t lose much since most rails projects will be using the asset pipeline to perform minification. [1] videojs/video.js#1586 [2] videojs/video.js#1491 [3] https://github.com/CharlotteDunois/videojs-loopbutton
Confirming this is an issue, your entire public api for buttons and components is completely mangled vjs.zencdn.net/4.11.4/video.js What is the work around ? Building the dev project is incredibly difficult with no documentation either. Would uglify on the dev source found in the zip be the best way ? |
@danrossi as the title of the issue suggests, we recognize the problem and are planning to move away from GCC in the next major version. That being said, what are you looking to do that you're having trouble with? Creating custom components? As far as building the player, the contributing guide contains pretty detailed information on how to do everything from build to submit PRs, etc. It's not as daunting as it looks, though, it can be as simple as this:
|
I've minified the dev version UglifyJS video.dev.js --mangle -c >> video.dev.min.js works comes in at 91kb. One of the components anyway trying to add a similar component as the error display alot of those public methods are mangled internally.
That is alot of stuff to install just to get a minified dist file ! It shouldn't require node just to do that. I should be able to just run a makefile which runs UglifyJS video.dev.js --mangle -c >> video.dev.min.js no idea. Its still trying to install stuff after 5 minutes and stuck here gyp http GET http://nodejs.org/dist/v0.10.26/node-v0.10.26.tar.gz I certainly don't need node to get a file that is all. It took me hours to figure out why something wasn't working and it led me here :D After a long while it ask me to sudo. Was it sudo npm install ? "Please try running this command again as root/Administrator." |
sudo npm install seemed to help. I get this when running it grunt
It may not help my situation if the public methods are being mangled no worries. This might help others just use uglify to minify the dev source I guess. |
Ahh sorry about that, I totally misunderstood you. If all you want is the dev version, you can find it in the zip (like you said originally) or in the dist folder of the stable branch. That's strange about the grunt-karma install failure, though...Travis runs In your example, off the top of my head all of those methods should be available in the current minified version. What specifically are you running into trouble with? We're definitely moving away from GCC, but we use tools like Grunt and others really heavily, so the Node requirement isn't going anywhere :) |
Just a quick thought on this. Have you guys compared Uglify vs Closure with only simple optimizations? In my experience, Closure still wins (although by less of a margin). But, I haven't tested Uglify in a while, so maybe they have made some improvements. |
The issue with GCC is that it also requires java. |
True. I don't know much about the current state of the project, but it seems to me that if you already have advanced optimizations working, it should be quite easy to switch to simple. No? |
Yeah, I guess it shouldn't be hard to switch, I'd like to to get rid of the java dependency. Also, we're planning to move to a more "standard" file naming conventions (#1013), so, the main file which will be unminified will be |
+1 for the standard naming convention. That would be great. I can understand wanting to remove a dependency. I would just recommend comparing Closure Simple vs Uglify first to see if it's worth it to keep closure (and Java) or not. |
I really don't think that the difference is really big enough to matter. Also, we'll probably go through and optimize the uglify build a bit rather than just using the defaults. |
Sure thing. I just thought it would be a good idea to check them both, and see what the difference is. Back when I first checked, Closure Simple was about 80% of the size of Uglify. Thanks again for a great piece of software. |
@dominic-p if you want to help us out and run a comparison of the two on the codebase, it wouldn't hurt to know either way. |
Discussion is always good :) |
@heff, good idea. I probably could have saved us all some time if I did that upfront. :) I ran some very basic tests on the current |
Great! Thanks for doing that. Now we know for sure. |
#1940 was submitted to address this issue if anyone would like to review. |
Closed by #1940. |
We're currently using Google's Closure Compiler with Advanced Optimizations to get better minification of video.js, at least in comparison to uglifyjs using all the compression options.
Part of getting to that level of minification is requiring that we whitelist any API property or function that should be accessible by name after minificaiton, using
exports
orexterns
. That in itself isn't necessarily a bad thing. It means we're deliberate about what we expose, and allows us to change major internal pieces of the player without worrying that we're breaking external code or plugins.However as more plugins have been built on top of video.js we've had a ton of requests for exporting additional properties, many of which we just overlooked. There's also the issue of sub-classing video.js components, like
videojs.Button
. To allow sub-classing we can't simplyexport
methods, which makes a copy of them. We have toextern
them, which prevents them from ever being mangled. Moving to externs for all components would create a lot of extra work and would also reduce some of the closure compiler benefit. (I'm not exactly sure how much, but before we started more aggressively exporting/externing properties the uglify version was over 50% bigger.)If we were only exposing the player API this might be a different story, but video.js is also part UI library and part utility library, and those other pieces can be just as valuable to plugin developers. Exposing those other pieces means there's going to be more things that are exported than are not.
Enough background... I'm hoping to get feedback on a few things.
As a half answer to #2, I did some manual minification tests to see what different approaches could do for us if possible.
component.prototype.method =
- savings of about 5k.The text was updated successfully, but these errors were encountered: