From 5a98faf78c53346e682bbdd79c7dd96f8bbfb6ee Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sat, 28 Mar 2015 17:37:41 +1030 Subject: [PATCH] Precompile inline templates Removing the in-browser compiler will save up to 30 kB (after minification + gzipping) and boost startup performance. Win! --- framework/core/ember/Brocfile.js | 8 +------- .../ember/app/components/application/user-dropdown.js | 3 ++- framework/core/ember/app/components/user/user-card.js | 6 ++++-- framework/core/ember/package.json | 1 + 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/framework/core/ember/Brocfile.js b/framework/core/ember/Brocfile.js index d8229cc53..0e4a4a415 100644 --- a/framework/core/ember/Brocfile.js +++ b/framework/core/ember/Brocfile.js @@ -2,13 +2,7 @@ var EmberApp = require('ember-cli/lib/broccoli/ember-app'); -var app = new EmberApp({ - vendorFiles: { - 'handlebars.js': null - } -}); - -app.import('bower_components/ember/ember-template-compiler.js'); +var app = new EmberApp(); app.import('bower_components/bootstrap/dist/js/bootstrap.js'); app.import('bower_components/spin.js/spin.js'); diff --git a/framework/core/ember/app/components/application/user-dropdown.js b/framework/core/ember/app/components/application/user-dropdown.js index 6419124ee..a35b49b7b 100644 --- a/framework/core/ember/app/components/application/user-dropdown.js +++ b/framework/core/ember/app/components/application/user-dropdown.js @@ -32,7 +32,8 @@ export default DropdownButton.extend(HasItemLists, { if (this.get('user.groups').findBy('id', '1')) { items.pushObjectWithTag(Ember.Component.extend({ tagName: 'li', - layout: precompileTemplate('{{fa-icon "wrench"}} Administration') + baseURL: config.baseURL, + layout: precompileTemplate('{{fa-icon "wrench"}} Administration') })); } diff --git a/framework/core/ember/app/components/user/user-card.js b/framework/core/ember/app/components/user/user-card.js index 536f0abd7..e69b31dac 100644 --- a/framework/core/ember/app/components/user/user-card.js +++ b/framework/core/ember/app/components/user/user-card.js @@ -3,6 +3,8 @@ import Ember from 'ember'; import HasItemLists from 'flarum/mixins/has-item-lists'; import UserBio from 'flarum/components/user/user-bio'; +var precompileTemplate = Ember.Handlebars.compile; + export default Ember.Component.extend(HasItemLists, { layoutName: 'components/user/user-card', classNames: ['user-card'], @@ -73,13 +75,13 @@ export default Ember.Component.extend(HasItemLists, { tagName: 'li', classNames: ['user-last-seen'], classNameBindings: ['hidden', 'user.online:online'], - layout: Ember.Handlebars.compile('{{#if user.online}}{{fa-icon "circle"}} Online{{else}}{{fa-icon "clock-o"}} {{human-time user.lastSeenTime}}{{/if}}'), + layout: precompileTemplate('{{#if user.online}}{{fa-icon "circle"}} Online{{else}}{{fa-icon "clock-o"}} {{human-time user.lastSeenTime}}{{/if}}'), user: this.get('user'), hidden: Ember.computed.not('user.lastSeenTime') }), 'lastActiveTime'); items.pushObjectWithTag(Ember.Component.extend({ - layout: Ember.Handlebars.compile('Joined {{human-time user.joinTime}}'), + layout: precompileTemplate('Joined {{human-time user.joinTime}}'), user: this.get('user') }), 'joinTime'); } diff --git a/framework/core/ember/package.json b/framework/core/ember/package.json index 3a859ce9f..d92cfda55 100644 --- a/framework/core/ember/package.json +++ b/framework/core/ember/package.json @@ -34,6 +34,7 @@ "ember-dynamic-component": "0.0.4", "ember-export-application-global": "^1.0.2", "ember-json-api": "eneuhauser/ember-json-api", + "broccoli-ember-inline-template-compiler": "tobscure/broccoli-ember-inline-template-compiler#f884d11", "express": "^4.8.5", "glob": "^4.0.5" }