Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>1) What language do you use at back-end?</p> <p>You can keep your script-configuration in database or in configuration files. (For example: page <code>page1</code> has modules: <code>module1</code>, <code>module2</code>, and <code>module4</code>, etc).</p> <p>I have such a php template file for generating <code>&lt;script&gt;</code> tags on my page:</p> <pre><code>&lt;script src="http://requirejs.org/docs/release/1.0.1/minified/require.js"&gt;&lt;/script&gt; &lt;script&gt; require([ &lt;?php echo "'". implode("',\n\t'", $this-&gt;scripts) . "'\n"; ?&gt; ], function(a){ function run(page) { if ( window.hasOwnProperty(page) ) { window[page].start(); } } var page = '&lt;?php echo $this-&gt;page; ?&gt;'; run('all'); // activating scripts needed for every page run(page); // and for current page }); &lt;/script&gt; </code></pre> <p>P.S. the script is asking for window[page] variable. I meant, that every .js script for a page -- for example <code>index.js</code> for <code>index</code> page is making <code>window.index</code> variable. ( I know, it's not so good - read P.P.S ;) )</p> <p><strong>P.P.S.</strong> I'm novice to requireJS (I've knew about it only today), and it my first draft, and I think, I'll make it in another way:</p> <p>2) As a concept for now :) You keep your scripts as AMD modules (not as usual scripts, but as modules for requireJS). Modules map you can keep in a <code>.json</code> file:</p> <pre><code>{ 'index' : [ 'news', 'banners' ], 'contacts' : [ 'maps', 'banners', 'donate' ], 'otherpage' : [ 'module1', 'module2' ] } </code></pre> <p>You should pass the page name or page id to the <code>main.js</code> (you can pass this value in DOM element - in templates of site, or in template variables ). So <code>main.js</code> knows the page name, and load your <code>modules.json</code> file. It gets specific modules and <code>requires</code> them.</p> <p><code>main.js</code> also can keep dependencies that are need on every page ( for example jquery, some jquery plugins, etc) ( jquery plugins better to wrap as modules )</p> <p>P.S. sorry for my English</p>
 

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