The type attribute, spaces and Opera browser
Debugging is part of my day job at Opera. Today, I stumbled across an issue related to white spaces and values for the HTML type attribute that affects Opera.
Take a look at the following code:
var d = 'test.js';
var s = document.createElement('script');
s.setAttribute("type", " text/javascript"); // note the leading space
s.src = d;
document.querySelector("body").appendChild(s);
That space between the " and text/javascript will cause Opera to fail. The script won’t load and or execute. Other browsers will handle that space with no problem, however. If you aren’t testing your site in Opera, you would miss this issue.
Keep in mind that this isn’t really a bug. It’s a difference in implementation. Opera is more strict about spaces in attributes than most browsers. The specification is either muddy or silent on this issue (depending on which version you consult). Yes, it’s something the development team is aware of and discussing internally. Yes, this also applies to the <script> tag.
In the meantime, make sure that you don’t include spaces at the beginning or end of the value of your type attributes.*
(Or leave it out if you’re using the HTML5 doctype.)