diff --git a/lib/less-browser/bootstrap.js b/lib/less-browser/bootstrap.js index 30193b5c..23ab02fe 100644 --- a/lib/less-browser/bootstrap.js +++ b/lib/less-browser/bootstrap.js @@ -3,7 +3,7 @@ * used in the browser distributed version of less * to kick-start less using the browser api */ -/*global window */ +/*global window, document */ // shim Promise if required require('promise/polyfill.js'); @@ -15,11 +15,31 @@ var less = module.exports = require("./index")(window, options); window.less = less; +var css, head, style; + if (options.onReady) { if (/!watch/.test(window.location.hash)) { less.watch(); } + // Simulate synchronous stylesheet loading by blocking page rendering + if (!options.async) { + css = 'body { display: none !important }'; + head = document.head || document.getElementsByTagName('head')[0]; + style = document.createElement('style'); + style.type = 'text/css'; + if (style.styleSheet) { + style.styleSheet.cssText = css; + } else { + style.appendChild(document.createTextNode(css)); + } + + head.appendChild(style); + } less.registerStylesheetsImmediately(); - less.pageLoadFinished = less.refresh(less.env === 'development'); + less.pageLoadFinished = less.refresh(less.env === 'development').then(function() { + if (!options.async) { + head.removeChild(style); + } + }); } diff --git a/lib/less-browser/file-manager.js b/lib/less-browser/file-manager.js index 81cb7e0c..d9727a1f 100644 --- a/lib/less-browser/file-manager.js +++ b/lib/less-browser/file-manager.js @@ -39,7 +39,7 @@ module.exports = function(options, logger) { FileManager.prototype.doXHR = function doXHR(url, type, callback, errback) { var xhr = getXMLHttpRequest(); - var async = options.isFileProtocol ? options.fileAsync : options.async; + var async = options.isFileProtocol ? options.fileAsync : true; if (typeof xhr.overrideMimeType === 'function') { xhr.overrideMimeType('text/css');