question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add missing semicolons to avoid minification issues

See original GitHub issue

This week we encountered an issue on the Bower website where we’re using this fetch polyfill.

Users were complaining a syntax error in our script that was compressed using Cloudflare’s “Auto minify” option. It turned out that the missing semicolons in this library are the cause of this issue. Here’s the reply from CloudFlare:

Auto minify will remove unnecessary characters from your source code (like whitespace, comments, etc.) without changing its functionality.

In other words it’ll not add missing ; to the end of lines. Thus, syntax errors appear.

I think that semicolons should be standard in general – even if not absolutely necessary, but I’d like to request this at least to avoid minification issues when processors are just removing the whitespace. Furthermore I’d like to request a .min.js file for this lib.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
ErisDScommented, Jul 4, 2017

I understand what you’re saying, as a repo maintainer, I fully get the point of view from which you’re coming at this and that adding maintenance overhead is painful.

As a user though, my perspective is very different. The code you’ve posted makes assumptions. I have to have node and npm installed, with versions that will work with the libraries you’re wanting me to use. I need to know to use the 3 npm libraries you’ve linked to (note: this issue thread started because someone used the wrong tool to minify the file).

As a frontend JS dev coming fresh to this repo, that’s a LOOOOOOOT of assumed knowledge. Scary and daunting.

I won’t waste any more of your time. I came to this repo, was put off by the lack of minified file, and decided that for my usecase it was just easier for now to add the ridiculous overhead of jQuery.

Instead of disappearing off without saying anything, I thought I’d take the time to let you know in case it helped someone else in future 🙂

2reactions
keithamuscommented, Jul 5, 2017

For anyone that reads through this looking for a solution for the use-case of wanting to use fetch but no having tooling, I’d recommend the use of Pollyfill.io which provides a drop-in script to update browsers to “evergreen standards” - it includes a fetch polyfill. One can simply drop the script tag in their HTML, no node, no npm, no uglify needed:

<script src="https://cdn.polyfill.io/v2/polyfill.min.js"></script>

The polyfill.io service is backed by Fastly’s CDN, so it’s plenty fast, it also has some smarts to it - it’ll only load the polyfill for browsers which need it, rather than for every browser! (If for some reason you want to force it to always load the fetch polyfill, just add ?features=fetch|always to the URL)

If you’re concerned about loading in other polyfills, and just want fetch with no other polyfills (other than what is required for fetch to work) then you can change the URL to the following:

<script src=https://cdn.polyfill.io/v2/polyfill.min.js?features=none,fetch"></script>

(Again, change this to ?features=none,fetch|always and it’ll always load fetch in every browser, even the ones that don’t need it).

N.B. It’s worth noting that Polyfill.io’s fetch polyfill uses this repo’s source.

Read more comments on GitHub >

github_iconTop Results From Across the Web

minify - In JavaScript, is it safe to omit semicolons when file ...
Missing semicolons can cause issues even if your code is not minified. It's always a good idea to use semicolons. I'd expect a...
Read more >
SyntaxError: missing ; before statement - JavaScript | MDN
The JavaScript exception "missing ; before statement" occurs when there is a semicolon ( ; ) missing somewhere and can't be added by...
Read more >
Re: issue with Javascript Fetch call - Adobe Experience League ...
Most likely an issue with the plugin that you're using. Try npm route if gcc doesn't work. Check -. Add missing semicolons to...
Read more >
Is it actually true that minifiers break JS code if semicolons are ...
This is a great answer. It's not the minification, rather the concatenation that will create syntax errors due to missing semicolons. Consider ...
Read more >
Semicolons in JavaScript: To Use or Not to Use?
Which basically means a semicolon will be added at the end of the file if it's missing one. 3- There are certain places...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found