PERF: speed up css precompilation by caching
This commit is contained in:
parent
28f84ef0e1
commit
f602c568e2
|
@ -18,20 +18,40 @@ task 'assets:precompile:before' do
|
||||||
require 'digest/sha1'
|
require 'digest/sha1'
|
||||||
|
|
||||||
module ::Sprockets
|
module ::Sprockets
|
||||||
class UglifierCompressor
|
|
||||||
def evaluate(context, locals, &block)
|
|
||||||
|
|
||||||
digest = Digest::SHA1.hexdigest(data)
|
def self.cache_compiled(type, data)
|
||||||
key = "SPROCKETS_#{digest}"
|
digest = Digest::SHA1.hexdigest(data)
|
||||||
|
key = "SPROCKETS_#{type}_#{digest}"
|
||||||
if compiled = $redis.get(key)
|
if compiled = $redis.get(key)
|
||||||
$redis.expire(key, 1.week)
|
$redis.expire(key, 1.week)
|
||||||
else
|
else
|
||||||
compiled = Uglifier.new(:comments => :none).compile(data)
|
compiled = yield
|
||||||
$redis.setex(key, 1.week, compiled)
|
$redis.setex(key, 1.week, compiled)
|
||||||
end
|
|
||||||
compiled
|
|
||||||
end
|
end
|
||||||
|
compiled
|
||||||
|
end
|
||||||
|
|
||||||
|
class SassCompressor
|
||||||
|
def evaluate(context, locals, &block)
|
||||||
|
::Sprockets.cache_compiled("sass", data) do
|
||||||
|
::Sass::Engine.new(data, {
|
||||||
|
:syntax => :scss,
|
||||||
|
:cache => false,
|
||||||
|
:read_cache => false,
|
||||||
|
:style => :compressed
|
||||||
|
}).render
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class UglifierCompressor
|
||||||
|
|
||||||
|
def evaluate(context, locals, &block)
|
||||||
|
::Sprockets.cache_compiled("uglifier", data) do
|
||||||
|
Uglifier.new(:comments => :none).compile(data)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue