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

Constant caching #761

Closed
fabiosantoscode opened this issue Aug 4, 2015 · 3 comments
Closed

Constant caching #761

fabiosantoscode opened this issue Aug 4, 2015 · 3 comments

Comments

@fabiosantoscode
Copy link
Contributor

Could we cache constants? Some strings (such as 'undefined', 'function', etc.), undefined, null, true, false, are used a lot! In unsafe mode, we could even cache Array.prototype, Object.prototype, [].slice (as in [].slice.call(arguments)). Large numbers may also be worth it to cache.

Declaring more safely cacheable things (such as window, document, document.documentElement, console, navigator) through an option could help us cache a ton of things.

@nickkolok
Copy link

It is said that gzip does it better and uglifier shouldn't do his work.

@fabiosantoscode
Copy link
Contributor Author

You might be right, but if gzip could take all he load for this, we wouldn't even shorten true and false to !0 and !1.

If I recall correctly, jquery caches some strings and undefined. I don't think they would do it if it didn't bring anything to the table after gzip.

@nickkolok
Copy link

Even gzipped, file with !0 instead of true is ~2 bytes shorter - it depends on Haffman 's results.

I'm not sure, but I think that jQuery caches this variables - not strings! - not for shortening, but for safety. undefined, window and document can be redefined, so jQuery caches them into it's closure to avoid such errors.

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

3 participants