Giter Site home page Giter Site logo

Comments (2)

phoboslab avatar phoboslab commented on July 18, 2024

The build.sh concatenates all .js files and runs it through uglifyjs. Assigning global objects to local names helps uglifyjs to squeeze out a few extra bytes in the minified file if these objects are used often.

E.g. consider:

for (var i = 0; i < Math.PI*2; i+=0.1) {
	var x = Math.sin(r);
	var y = Math.cos(r);
	draw(x, y);
}

Will be minified to:

for(var a=Math,h=0;h<2*Math.PI;h+=.1){var t=Math.sin(r),M=Math.cos(r);draw(t,M)}

If we assign the global Math to a local var:

var _math = Math;
for (var i = 0; i < _math.PI*2; i+=0.1) {
	var x = _math.sin(r);
	var y = _math.cos(r);
	draw(x, y);
}

We will end up with:

for(var a=Math,v=0;v<2*a.PI;v+=.1){var d=a.sin(r),f=a.cos(r);draw(d,f)}

Maybe uglifyjs has a flag to do this automatically? I don't know. It worked out fine for my project, though.

from underrun.

adrianblynch avatar adrianblynch commented on July 18, 2024

Thanks @phoboslab.

Really good game!

from underrun.

Related Issues (7)

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.