From: Jakub Pawlowicz Date: Thu, 3 Nov 2016 18:57:34 +0000 (+0100) Subject: See #260 - delays Worker initialization. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=3083254eb7bf002503ff9c44842c586077efec91;p=clean-css.git See #260 - delays Worker initialization. Why: * There's no point fetching CleanCSS until files are about to be optimized. * It currently uses a fixed version of CleanCSS but we'll pass version to initializer once more versions are supported. --- diff --git a/docs/js/drag-drop.js b/docs/js/drag-drop.js index db157afa..1a3cdc0d 100644 --- a/docs/js/drag-drop.js +++ b/docs/js/drag-drop.js @@ -12,6 +12,8 @@ function fileDraggedIn(event) { event.preventDefault() event.dataTransfer.dropEffect = 'copy' + + Optimizer.initialize() } function fileDraggedOver(event) { diff --git a/docs/js/optimizer-worker.js b/docs/js/optimizer-worker.js index 3fc880d6..cf51d14a 100644 --- a/docs/js/optimizer-worker.js +++ b/docs/js/optimizer-worker.js @@ -1,8 +1,13 @@ -onmessage = function(event) { - if (!event.data) - return +var initialized = false +onmessage = function(event) { switch (event.data.command) { + case 'initialize': + if (!initialized) { + initialized = true + importScripts('//jakubpawlowicz.github.io/clean-css-builds/v3.4.20.js') + } + break case 'optimize': new CleanCSS(event.data.options).minify(event.data.input, function (error, output) { postMessage({ @@ -16,4 +21,4 @@ onmessage = function(event) { } } -importScripts('//jakubpawlowicz.github.io/clean-css-builds/v3.4.20.js') + diff --git a/docs/js/optimizer.js b/docs/js/optimizer.js index b6460f3b..b4045709 100644 --- a/docs/js/optimizer.js +++ b/docs/js/optimizer.js @@ -14,6 +14,12 @@ Optimizer = { } }, + initialize: function() { + this.worker.postMessage({ + command: 'initialize' + }) + }, + process: function (id, styles) { this.worker.postMessage({ command: 'optimize',