Coder Social home page Coder Social logo

Generate more compessor-friendly javascript about jsil HOT 3 OPEN

sq avatar sq commented on August 10, 2024
Generate more compessor-friendly javascript

from jsil.

Comments (3)

kg avatar kg commented on August 10, 2024

How does that help compressors specifically? It looks like the resulting JS would be larger and more complicated, so I don't know how that would help the compressor. Is there a specific compressor that struggles with the way the code works now so I can take a look?

from jsil.

dimzon avatar dimzon commented on August 10, 2024

Google Closure Compiler, Yahoo Compressor and other good compressors can rename local variables and parameters (_$$System$Drawing$Bitmap$prototype) to something one-letter:

(function(){
 ...
 var a = System.Drawing.Bitmap.prototype;
 a._ctor$1 = function (x, b) {
 a._ctor$0.call(this, x);
 };
 ...
 })();

So You can use long significant names for local variables (to maintain readability) BUT compiler will optimize it reducing javascript size a lot.

the best way is to make JSIL.MakeClass to return a function itselt so you can generate something like this

//Trick: using unassigned parameter instead local variable definition (,v instead var v will save some chars)
(function(_$$System$Drawing$Bitmap,_$$System$Drawing$Bitmap$prototype){
_$$System$Drawing$Bitmap$prototype=_$$System$Drawing$Bitmap.prototype;
// Class definition below
 _$$System$Drawing$Bitmap$prototype._ctor$1 = function (filename, b) {
 _$$System$Drawing$Bitmap$prototype._ctor$0.call(this, filename);
 };
})(JSIL.MakeClass(.....));

from jsil.

dimzon avatar dimzon commented on August 10, 2024

other trick is to use object['field'] instead of object.field notation
look at this sample

  1. unoptimized original code
obj.prototype.foo=....;
obj.prototype.bar=....;
obj.prototype.aaa=...;
  1. prepared code
var $prototype='prototype'; // must be LOCAL variable
obj[$prototype].foo=....;
obj[$prototype].bar=....;
obj[$prototype].aaa=...;
  1. prepared after compilation (LOCAL variable names will be shortened to 1 char)
var p='prototype'; // must be LOCAL variable 
obj[p].foo=....;
obj[p].bar=....;
obj[p].aaa=...;

this trick works great if you combine whole assembly definition into one anonimous function and apply this trick for wide-used "apply" "call" "prototype" etc

from jsil.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.