Skip to content

Instantly share code, notes, and snippets.

@fabiomontefuscolo
Created May 7, 2014 14:25
Show Gist options
  • Save fabiomontefuscolo/2e3ca358afc2edeb10ec to your computer and use it in GitHub Desktop.
Save fabiomontefuscolo/2e3ca358afc2edeb10ec to your computer and use it in GitHub Desktop.
In HTML5 page, I try to load a CSS generated by Less. When the CSS does not exist, I fallback to Less file.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Fallback to Less</title>
<script type="text/javascript">
function fallbackToLess(){
var script = document.createElement('script');
script.src = "js/libs/less-1.7.0.min.js";
script.type = "text/javascript";
document.head.appendChild(script);
var link = document.createElement('link');
link.href = "less/styles.less";
link.rel = "stylesheet/less";
document.head.appendChild(link);
less.sheets.push(link)
less.refresh()
}
</script>
<link href="css/styles.css" rel="stylesheet" onerror="fallbackToLess()"/>
</head>
<body>
<h1>The html5 page</h1>
<p> ...</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment