Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is the way I structure my application :</p> <p>I have a javascript path, which I'm minifying on demand by the server when client access "/javascript", so I have only one script line in my index.html :</p> <pre><code>&lt;script src='/javascript'&gt;&lt;/script&gt; </code></pre> <p>My directory structure of /javascript is the following :</p> <pre><code>application.js router.js lib/ lib/jquery.js lib/underscore.js lib/backbone.js lib/require.js lib/other_libraries.js views/ views/navigation.js views/overlay.js views/content.js views/page views/page/constructor.js views/page/elements views/page/elements/constructor.js views/page/elements/table.js views/page/elements/form.js views/page/elements/actions.js collections/ collections/paginated.js </code></pre> <p>All those files are minified and loaded from client in the first request. By doing this I have a lot of my code already loaded in my browser before the application makes any requests with RequireJS.</p> <p>On my server I have a directory, which is also public, but is for dynamic javascript loading and templates ( it is accessed by demand from the application at any given time ). The directory looks like this :</p> <pre><code>dynamic/ dynamic/javascript dynamic/javascript/pages dynamic/javascript/pages/articles.js dynamic/templates dynamic/templates/pages dynamic/templates/pages/articles.hb dynamic/templates/pages/items.hb </code></pre> <p>When my server requests "/templates/pages/articles.hb" the server returns JSON object which looks like this :</p> <pre><code>{ html : "&lt;div class='page' id='articles'&gt;blah blah blah&lt;/div&gt;", javascript : "javascript/pages/articles.js" } </code></pre> <p>And when my client app receives "javascript" property in the returned JSON object it triggers a RequireJS request</p> <pre><code>if ( typeof json.javascript === string ) { require([ json.javascript ], function(constructor) { window.app.page = new constructor(); }); } </code></pre> <p>In the dynamic/javascript/pages/articles.js I have something like :</p> <pre><code>define(function() { var Model = Backbone.Model.extend({}); // Collections.Paginated is in fact the Collection defined by /javascript/collection/paginated.js // it is already loaded via the initial javascript loading var Collection = Collections.Paginated.extend({ url : '/api/articles' }); // Views.Page is in fact the View defined by /javascript/views/page/constructor.js // it is also already loaded via the initial javascript loading var articles = Views.Page.extend({ collection : Collection, initialize: function(options) { this.collection = new Collection(); }); }); return articles; }); </code></pre> <p>Pretty much that's it. I have minimum requests with RequireJS, because every time you hit require('something.js') it makes a request to the server, which is not good for your application speed.</p> <p>So the exact answer of your question ( in my opinion ) is : You should make your initial loaded files separated as much as possible, but later loaded files with requireJS should be as small as possible to save traffic.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload