Blog About Contact

MHTML Browser Compatibility - CSS Inlining

Published Thu, 15 Jul 2010

MHTML is a technology implementing by Microsoft in Internet Explorer for packaging images, stylesheets and other resources inside a single HTML file. Typically this is used for things like help files, ebooks or other "published" content, but more recently has been proposed as a way of supporting CSS image inline in IE6 and IE7, which don't support "Data URIs".

MHTML is as far as I know, only implemented in Internet Explorer. And given that IE8 supports data URI's there's no reason to use it outside of IE6/IE7.

I've done some testing and, as cited in the comments of this thread on MHTML, there are issues with using MHTML to inline images in CSS on Windows Vista running IE7. This specific platform has problems and will not accept a CSS file with inlined MHTML images.

I tried fixing this, as some others have suggested, by separating the MHTML images into a separate file, and keeping the CSS by itself, referencing the MHTML file.

This appears to work -- at least, it works the first time. But a subsequent reload will then display blank images. Essentially the next time it reloads from the cache, it breaks.

That pretty much rules out using MHTML on Windows Vista, since the whole point of MHTML is to load one file rather than making multiple requests. If you can't cache the file, then there is no benefit!

What about other platforms?

Well on Windows XP, IE6 and IE7 appear to work just fine.

However - in some corporate environments there are browser security flags that may cause the inlined MHTML to not load initially. Subsequently you may get strange behaviour when the user does try to load them.

Update: I've resolved this one - this can occur when the MHTML content is not matched with appropriate MIME types and formatted as IE expects it. Most of the other articles about using MHTML in this manner do not adhere strictly to the MHTML format and exhibit this issue.

My Verdict

For the open-web, I'd suggest that MHTML is too much of a liability to use across the board. You really can't be sure that people are actually seeing your site as intended.

Update: Actually, if you have a Java web app, my ResourceTransformFilter will apply MHTML in a reliable way across your application - only to the clients that can use it.

If you have a controlled environment (e.g. intranet or WAN) then MHTML might be a valid choice, since you can be sure that the browser configuration is suitable for your served content.

At least the future for Data URI's is bright and as IE6/IE7 market share shrinks this whole issue will disappear.


About the Author

Richard Nichols is an Australian software engineer with a passion for making things.

Follow him on twitter or subscribe by RSS or email.

You might also enjoy reading -


Discuss / Comment

No one has commented yet.

Add a comment

  • {{e.error}}

Thanks for your comment!/

Required.
Valid email address required.
Required.
Posting message, please wait...