mirror of
https://github.com/less/less.js.git
synced 2026-01-21 05:08:10 -05:00
Fix for #2384 - fakes "sync" loading of web page by hiding it until styles are done
/ The actual XHR requests are changed to async for a speed boost for "sync" loading of orders of magnitude
This commit is contained in:
24
lib/less-browser/bootstrap.js
vendored
24
lib/less-browser/bootstrap.js
vendored
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user