Using Gulp to Add UTF8 BOM for Windows 10 Javascript Apps

Continuing Discussion from:

HTML+JS apps have had their application load times accelerated since Windows 8 with bytecode caching. This has improved for Windows 10 as now all js files will have their compiled byte code cached rather than just the ones referenced from the main html page:

In fact the Windows App Certification Kit won’t pass your HTML+JS app unless you do save as utf-8 and include a byte order mark for encoding.

This is on top of the data being local and not needing any network round trips so it becomes super fast. We still use the ASP.NET website to do most of the work; but have very fast start up and local images, scripts etc for some of it, which gets downloaded as part of the app install – giving the best of both worlds.

The suggested approach to add encoding byte order marks is to just use “Save As…” save with encoding in Visual Studio. But as we share the javascript between our ASP.NET webapp and our UWP Javascript app; we are already using a Gulp task to prepare our stuff for the web; so its not much of a step to extend this to add in the BOMs.

There seem to be a lot of npm, Gulp plugins and Grunt plugins to remove utf-8 byte order marks; but not many to actually add them – so we use the following code in our Gulpfile to do what a plugin would do: