User:Weeklyd3/Essays/Getting around ES5 linting

When writing a user script, sometimes, you may want to use ES6 JavaScript syntax like  and. However, to make MediaWiki's ResourceLoader load faster, MediaWiki minifies this JavaScript. So it has to run a check for syntax errors before minifying it (or risk messing up the minified JavaScript). The problem is, the functionality that checks the syntax doesn't support ES6 yet, so your common.js will simply refuse to run if it isn't valid ES5.

Getting around this
If you are sure you want to use ES6, you can place your code in a subpage that ends with, and use   (replacing   with the title of the script on-wiki) on your common.js to load it. When you use, MediaWiki just sends the JavaScript without checking it for syntax errors, so it is up to your browser if it wants to execute the ES6 or throw another syntax error.

Performance issues
Because you load a script which loads another script (loading two for the cost of one), this can result in slightly slower performance. On the other hand, it's not too hard to adapt ES6 into valid ES5 (transpilers like Babel.js actually can do this), so you may want to convert the ES6 to ES5 using one of these tools before publishing it.