Skip to content

Instantly share code, notes, and snippets.

@philmander
Created September 5, 2011 21:00
Show Gist options
  • Save philmander/1195905 to your computer and use it in GitHub Desktop.
Save philmander/1195905 to your computer and use it in GitHub Desktop.
Data URIs and automation with CSSEmbed and Ant 3
<script>
(function() {
function addStylesheet(dataUriHref, fallbackHref) {
var img = new Image();
img.onload = img.onerror = function() {
var link = window.document.createElement("link");
link.type = "text/css";
link.rel = "stylesheet";
link.href = this.width !== 1 ? fallbackHref : dataUriHref;
var head = document.getElementsByTagName("head")[0] || document.documentElement;
head.insertBefore(link, head.firstChild);
};
img.src = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";
}
addStylesheet("/css/site-datauri.css", "/css/site-mhtml.css");
})();
</script>
<noscript>
<link type="text/css" rel="stylesheet" href="/css/site.css" />
</noscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment