From 6423dc6643230463de9c73c3d19292228ba50570 Mon Sep 17 00:00:00 2001 From: 3rd-Eden Date: Fri, 27 Jun 2014 12:57:38 +0200 Subject: [PATCH] Revert "Revert "[major] Load CSS first and render instantly when the CSS is loaded, then load the JS."" This reverts commit e2a4767bab3ae82ebebe4f9678cb4ed9632dabe7. --- pagelet.js | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/pagelet.js b/pagelet.js index 069f7bd..b938ba4 100644 --- a/pagelet.js +++ b/pagelet.js @@ -160,27 +160,34 @@ Pagelet.prototype.configure = function configure(name, data, roots) { // pagelet.broadcast('configured', data); - async.each(this.css.concat(this.js), function download(url, next) { + async.each(pagelet.css, function download(url, next) { assets.add(url, next); }, function done(err) { if (err) return pagelet.broadcast('error', err); - pagelet.broadcast('loaded'); pagelet.render(pagelet.parse()); - // - // All resources are loaded, but we have a parent element. When the parent - // element renders it will most likely also nuke our placeholder references - // preventing us from rendering updates again. - // - if (parent) parent.on('render', function render() { - pagelet.placeholders = pagelet.$('data-pagelet', pagelet.name, parent.placeholders); - pagelet.listen(); - pagelet.render(pagelet.data || pagelet.parse()); - }); - - pagelet.initialize(); - }, { context: this.bigpipe, timeout: this.timeout }); + async.each(pagelet.js, function download(url, next) { + assets.add(url, next); + }, function done(err) { + // + // All resources are loaded, but we have a parent element. When the parent + // element renders it will most likely also nuke our placeholder references + // preventing us from rendering updates again. + // + // @TODO we need a pre-render event so we can clear assigned event + // listeners. + // + if (parent) parent.on('render', function render() { + pagelet.placeholders = pagelet.$('data-pagelet', pagelet.name, parent.placeholders); + pagelet.listen(); + pagelet.render(pagelet.data || pagelet.parse()); + }); + + pagelet.broadcast('loaded'); + pagelet.initialize(); + }, { timeout: pagelet.timeout }); + }, { timeout: pagelet.timeout }); }; /**