A few days ago, I stumbled upon a problem that I never really noticed before Google Chrome was released. It seems that Google Chrome chokes on embedded javascript if some weird bytes are present in the HTML.
It took a while to figure out what was going on. It seems the weird bytes were the byte order mark for UTF-8 documents (hex EF BB BF). When Google Chrome finds these bytes within a <script> block, it will simply stop parsing javascript. No errors, no warnings.
You can argue that this is a problem with Google Chrome, but that still doesn’t explain why these bytes were in my javascript blocks to start with.
The problem is this: I inject javascript in the HTML output from embedded resources. The embedded resources are just .js files created in Visual Studio, marked as “embedded resource”. The resource is then read from the assembly and converted to a UTF8 string and inserted in the HTML script block. The problem is that Visual Studio ALWAYS adds the UTF-8 “byte order mark” when you save a text file. These bytes are also embedded in the embedded resource, which is… annoying.
Of course, you could tell Visual Studio to save your file without signature (“byte order mark”), but you have to do that EVERY time you’ve created a new javascript file. There’s no way to make that the default.
Bummer…
On a positive note, this gives me the perfect excuse to announce the release of Release Candidate 2 of ProMesh.NET 2.0, which has built-in detection for BOM bytes on embedded resources








