Created
July 23, 2012 08:38
-
-
Save jhjguxin/3162645 to your computer and use it in GitHub Desktop.
LESS & automatic CSS cacheing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="http://lesscss.googlecode.com/files/less-1.0.18.min.js"></script> | |
<%= javascript_include_tag "application" %> | |
<%= stylesheet_link_tag "application", :media => "all", :id => "application_css"%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log("refreshing styles..."); | |
less.sheets.push(document.getElementById('application_css')); | |
less.refresh(true); | |
console.log("refreshed..."); | |
less.autoRefresh = function(time) | |
{ | |
var sheets = []; | |
for(var i = less.sheets.length; i--; ) | |
sheets.push(less.sheets[i].href); | |
setInterval( | |
function() | |
{ | |
for(var i = sheets.length; i--; ) | |
less.sheets[i].href = sheets[i] + '?'+Math.random(); | |
console.log("refreshing styles..."); | |
less.refresh(1); | |
console.log("refreshed..."); | |
}, | |
time || 1000 | |
); | |
var fnImport = less.tree.Import; | |
less.tree.Import = function(path, imports) | |
{ | |
path.value += '?x='+Math.random(); | |
fnImport(path, imports); | |
} | |
}; | |
jQuery(document).ready(function($){ | |
less.autoRefresh(time = 600000); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment