Skip to content

Commit

Permalink
don't load html-minifier js context until it is needed
Browse files Browse the repository at this point in the history
  • Loading branch information
sam0x17 committed Oct 3, 2019
1 parent c5dea76 commit 0ea2777
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/html-minifier.cr
Expand Up @@ -32,14 +32,16 @@ module HtmlMinifier
ctx.eval!("var minify = require('html-minifier').minify;")
ctx
end
@@ctx : Duktape::Sandbox = initialize_context
@@ctx : Duktape::Sandbox? = nil

def self.minify!(source : String)
@@ctx ||= initialize_context
ctx = @@ctx.not_nil!
source = source.gsub("\"", "\\\"")
source = source.gsub("\n", "\\n")
source = source.gsub("'", "\\'")
@@ctx.eval!("var output = minify(\'#{source}\', options);")
@@ctx.eval!("output")
@@ctx.get_string(-1).not_nil!
ctx.eval!("var output = minify(\'#{source}\', options);")
ctx.eval!("output")
ctx.get_string(-1).not_nil!
end
end

0 comments on commit 0ea2777

Please sign in to comment.