Using UglifyJS's screw-ie8 Option in Gulp
By default, UglifyJS writes JavaScript that works around IE 6-8 quirks. If you're building a modern app, those workarounds just add bloat. The screw-ie8 flag tells UglifyJS to skip those compatibility checks and produce smaller, faster code.
When UglifyJS minifies your code without this flag, it preserves behavior that IE8 expects—like how try/catch affects variable scope or how named function expressions work. These workarounds add bytes to your bundle and slow down execution in modern browsers. If you don't support IE8 (and you shouldn't), you're shipping compatibility code for a browser that died years ago.
From the command line, you'd use it like this:
cat input.js | uglifyjs --screw-ie8 -o output.js
Setting it up in Gulp
Most projects use build tools instead of running UglifyJS directly. Here's the full Gulp task:
var minifier = require('gulp-uglify/minifier')
var uglifyjs = require('uglify-js')
var rename = require('gulp-rename')
gulp.task('uglify', function () {
return gulp.src(['js/*.js'])
.pipe(minifier({
compress: {
screw_ie8: true
},
mangle: {
screw_ie8: true
}
}, uglifyjs))
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest('dist'))
})
Notice I'm using gulp-uglify/minifier instead of the standard gulp-uglify. This lets me pass my own version of uglify-js and gives more control over which UglifyJS version runs. The screw_ie8 flag needs to be set in both compress and mangle options to fully remove IE8 compatibility code. The gulp-rename plugin adds .min to the filename so the original and minified versions can coexist.
With screw_ie8: true, UglifyJS removes workarounds for IE8's broken try/catch scoping, handles named function expressions normally instead of working around IE8 bugs, produces shorter variable names without IE8 reserved word restrictions, and skips checks for IE8-specific edge cases. The result is smaller bundles and faster execution in every browser that matters.
In 2016, IE8 usage was already negligible. Microsoft ended support for it in January 2016. If you're still coding for IE8 compatibility, you're optimizing for a dead platform at the expense of everyone else. This flag is about making a choice: support modern browsers well, or support dead browsers poorly. Choose modern.
Microsoft understood this too. That same year, Edge 14 caught up with Firefox on web standards, showing they were finally moving past the IE era.
Build tools have evolved significantly since 2016. Gulp is still around, but modern alternatives like Vite handle minification and optimization with less configuration and better performance.