Some minifications suggestions
kimgiutae opened this issue · 1 comments
Great work! I really like this kind of tiny masterpieces, instead of overcomplicated stuff soo common nowadays... This is not an issue at all. Just a few suggestions to get the code even smaller after minification.
1_ cache prototype object:
var proto = MoveTo.prototype
;
Before minification:
var proto = MoveTo.prototype:
proto.registerTrigger = function(){ };
proto.move = function(){ };
proto.addEaseFunction = function(){ };
After minification:
var p=MoveTo.prototype:p.registerTrigger=function(){};p.move=function(){};p.addEaseFunction=function(){};
Minification without caching:
MoveTo.prototype.registerTrigger=function(){};MoveTo.prototype.move=function(){};MoveTo.prototype.addEaseFunction=function(){};
2_ save some methods and properties in strings, and later use brackets notation. For example, the getAttribute methods:
Before minification:
var _getAttribute = 'getAttribute':
var attr1 = elem[_getAttribute]('data-attr-1');
var attr1 = elem[_getAttribute]('data-attr-2');
var attr3 = elem[_getAttribute]('data-attr-3');
After minification:
var a='getAttribute',b=e[a]('data-attr-1'),c=e[a]('data-attr-2'),d=e[a]('data-attr-3');
Minification without caching:
var b=e.getAttribute('data-attr-1'),c=e.getAttribute('data-attr-2'),d=e.getAttribute('data-attr-3');
You can "cache" some others objects/properties more... like "forEach"
Yeah... I know that the differences are insignificant, but is a good practice and even more important if you plan to extend some functionality or add more methods to the constructor...
Anyway good work!
Hi @giutae
This kind of caching things does not make a positive impact on gzip. I tested your suggestions. After do caching somethings, yes min.js
file size reduced but I can not say that for gzip;
As you see, do the things you mentioned above is decreasing the gzip performance.
Sory for the late reply, thank you.