pyrsmk / toast

A modern JS/CSS asset loader, written in TypeScript.
MIT License
118 stars 13 forks source link

add a semicolon in the beigin #9

Closed jabez128 closed 10 years ago

jabez128 commented 10 years ago

add a semicolon in the beigin for minifying

pyrsmk commented 10 years ago

Why is it needed?

jabez128 commented 10 years ago

for example, if you have two self-invoking function:

a.js
(function(){ //do something a})()

b.js
(function(){//do something b})()

when you concatenate the two js files together, the result file will look like :

(function(){ //do something a})()(function(){//do something b})()

You have two statements without separator. This happens when you cat files together and then minify them.

so if you put a semicolon in the beginning, the result file will look like:

;(function(){ //do something a})();(function(){//do something b})()

it will be safe and sound, especially in large project.

pyrsmk commented 10 years ago

Interesting... I should do the same modification to my other libraries. Thanks!