TL;DR: Yes, it’s permissible to omit closing /
on an image tag, but my plugin (and others) won’t recognize it.
It’s true that HTML5 doesn’t need to have a trailing slash on an image tag. However, due to the complexities of parsing HTML in PHP, I’ve made the decision that this plugin will require valid XHTML in order to find objects to be lazy-loaded. This plugin uses regex to locate HTML tags and replace src
with data-src
. Correctly identifying when a tag opens and closes in PHP becomes incredibly complicated for a myriad of reasons when you don’t have well-formed XML (which is permissible in HTML5).
I have made the decision that it is safer to miss a few tags which aren’t XHTML-compliant rather than risk incorrectly matching additional HTML content. (Missing an img
is better than finding an img
that’s not really an img
). This is one of the arguments for continuing to adhere to XHTML despite the relaxed stance taken in HTML5. I’m not really invested in that argument one way or the other, but for the purposes of this plugin, HTML needs to be in that format.
Feel free to make that call for yourself. There’s no real downside (aside from the time it takes to fix it) of making your markup XHTML compliant, and the upside is that this plugin, and other similar plugins will work with it.