Skip to content Skip to sidebar Skip to footer

In Javascript, Is It Safe To Omit Semicolons When File Have To Be Minifyed?

Since a few week, I omit semicolons in my JavaScript files. I realized today it may cause issues if the file is minifyed. I read the following ressources: https://www.reddit.com/

Solution 1:

It shouldn't cause problems, as long as the minifier does not have bugs within it.

This is because JavaScript code without semicolons is perfectly valid, parseable JavaScript.

And this can be accurately and reproducibly minified.

No "guesswork" will be involved - only a well-defined, deterministic parsing algorithm, based on the specification.

Bugs have previously been identified in minifiers related to ASI.

So depending on the maturity of the minifier, there might be an increased risk of hitting such a bug.

That said, bugs have previously been found in minifiers unrelated to ASI too, so there will always be a risk that your minifier introduces a problem, regardless of whether you use semicolons or not.

Given all this, and the high quality and maturity of JavaScript minifiers, I would follow the coding style that makes your team happiest.

Post a Comment for "In Javascript, Is It Safe To Omit Semicolons When File Have To Be Minifyed?"