Comments (3)
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.
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.
other trick is to use object['field'] instead of object.field notation
look at this sample
- unoptimized original code
obj.prototype.foo=....;
obj.prototype.bar=....;
obj.prototype.aaa=...;
- prepared code
var $prototype='prototype'; // must be LOCAL variable
obj[$prototype].foo=....;
obj[$prototype].bar=....;
obj[$prototype].aaa=...;
- 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)
- DCE works incorrectly for derived interface implementation
- Content Not Being Generated XNA HOT 1
- Assembly.GetType is not working for generics.
- Unsigned comparisons work incorrect
- Type.FullName is not returning correct name for generic dictionary
- Async state machine incorrect translation HOT 6
- Calling External Library From C# HOT 2
- string.IndexOf(String value, StringComparison comparisonType) not available HOT 2
- Support netstandard assemblies
- ulong math is incorrect HOT 2
- Installing JSIL on Linux HOT 2
- Support pascalabc
- InvalidCastException when using Newtonsoft.Json.dll (10.0.1 .NET 4.0) HOT 1
- Delegate.Method fails when called in constructor. HOT 3
- C# 7.2 "in" keyword in interfaces
- DateTime Object does not implement public functions
- load file
- Attribute properties are missing HOT 1
- How to Convert a CSharp Project to JavaScript on a Mac? HOT 2
- where do I find the namespace and game?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsil.