javascript - Backbone.js rendering delay? -
im new backbone , there 1 problem cant figure out. use backbone require.js. when want render view first time (when reload page in browser) index.html shows hidden 2 seconds , showed again rendered templates. if navigate between views (without hitting refresh) works smooth, initial render wrong. here code:
view:
define(['jquery','underscore','backbone', 'text!../../../templates/home/homeview.tpl'], function($, _, backbone, hometemplate) { var homeview = backbone.view.extend( { events:{ }, render: function () { var template = _.template(hometemplate); this.$el.html(template); return this; } }); return homeview; });
router:
define(['jquery','underscore','backbone'], function($, _, backbone) { var container = $("#container"); var approuter = backbone.router.extend( { routes: { "": "home" }, home: function() { require(['views/home/homeview'], function(homeview) { var home = new homeview({el: container}); home.render(); }); } }); var initialize = function() { var app_router = new approuter(); backbone.history.start(); }; return { initialize: initialize }; });
i no error in console. behavior normal?
it normal.
rquirejs loads dependencies via http requests , these requests have timeouts. additionally in browsers there limit maximum parallel downloads. these delays can add 2 seconds @ startup combined network latency.
if want minimize delay, minimize files r.js mentioned in requirejs docs.
edit: if minify won't solve problem, browser profiling tool can you.
Comments
Post a Comment