Permalink
Browse files

Add cache busting for in-browser LESS compiler [#98 state:resolved]

  • Loading branch information...
1 parent e3fc728 commit 4344a851463c9c6aa7deff335d6f2cc8d76f6dd9 @andreyvit andreyvit committed Nov 18, 2011
Showing with 20 additions and 7 deletions.
  1. +19 −6 src/less.coffee
  2. +1 −1 src/livereload.coffee
View
@@ -6,12 +6,25 @@ module.exports = class LessPlugin
constructor: (@window, @host) ->
reload: (path, options) ->
- console.log [path, options]
- if (path.match(/\.less$/i) || options.originalPath.match(/\.less$/i)) and @window.less and @window.less.refresh
- @host.console.log "LiveReload is asking LESS to recompile all stylesheets"
- @window.less.refresh(true)
- return true
- false
+ if @window.less and @window.less.refresh
+ if path.match(/\.less$/i)
+ return @reloadLess(path)
+ if options.originalPath.match(/\.less$/i)
+ return @reloadLess(options.originalPath)
+ no
+
+ reloadLess: (path) ->
+ links = (link for link in document.getElementsByTagName('link') when link.href and link.rel is 'stylesheet/less' or (link.rel.match(/stylesheet/) and link.type.match(/^text\/(x-)?less$/)))
+
+ return no if links.length is 0
+
+ for link in links
+ link.href = @host.generateCacheBustUrl(link.href)
+
+ @host.console.log "LiveReload is asking LESS to recompile all stylesheets"
+ @window.less.refresh(true)
+ return yes
+
analyze: ->
{ disable: !!(@window.less and @window.less.refresh) }
View
@@ -106,7 +106,7 @@ exports.LiveReload = class LiveReload
# official API
console: @console
Timer: Timer
- generateCacheBustUrl: (url) -> @reloader.generateCacheBustUrl(url)
+ generateCacheBustUrl: (url) => @reloader.generateCacheBustUrl(url)
# API that pluginClass can/must provide:
#

0 comments on commit 4344a85

Please sign in to comment.