Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>How are you defining your require.config? I think for it to take effect before you import require.js, you need to code it like this:</p> <pre><code>&lt;script type="text/javascript"&gt; var require = { baseUrl: "/scripts/", waitSeconds: 15, urlArgs : "bust="+new Date().getTime() }; &lt;/script&gt; &lt;script data-main="app/main" src="/scripts/require.js"&gt;&lt;/script&gt; </code></pre> <p>Specifically, a an object named 'require' must be constructed before you import require.js.</p> <p><strong>UPDATE</strong></p> <p>As Jesse points out in the comments below, there are a few enhancements you should apply to your require{} object for production use. The above example is cribbed from the RequireJS documentation and modified as little as possible to answer this question.</p> <p>Here are a few things to consider for production use: </p> <ul> <li>Instead of using the current date-time as your cache-busting variable, you should use a build number from your development environment. This allows your clients to cache the Javascript between releases but will cause them to refresh their cache whenever you do a software update.</li> <li>Jesse also uses the require{}'s ability to specify dependencies instead of using the data-main attribute of the script. I don't know if that is strictly <em>better</em>, but I think it is cleaner looking.</li> <li>Adjust the waitSeconds based on your needs. I used the example value from the RequireJS documentation, but you should adjust the value or omit it, based on your needs.</li> </ul> <p>So if you apply these techniques, your code might look like:</p> <pre><code>&lt;script type="text/javascript"&gt; var require = { baseUrl: "/scripts/", waitSeconds: 15, urlArgs : "bust="+{{buildNumber}}, deps : ['app/main'] }; &lt;/script&gt; &lt;script src="/scripts/require.js?bust={{buildNumber}}"&gt;&lt;/script&gt; </code></pre> <p>Note, in this case {{buildNumber}} is a value supplied by the server.</p> <p><strong>UPDATE 2</strong></p> <p>The urlArgs cache bust solution has problems. Unfortunately you cannot control all proxy servers that might be between you and your user's web browser. Some of these proxy servers can be unfortunately configured to ignore URL parameters when caching files. If this happens, the wrong version of your JS file will be delivered to your user.</p> <p>I would recommend using a <code>buildNumber</code> <em>in</em> your Javascript filename request, like <code>buildNumber.myModule.js</code> (prefix) or myModule.buildNumber.js (postfix). You can use the prefix style by modifying the baseUrl:</p> <pre><code>baseUrl: "/scripts/buildNumber", </code></pre> <p>Note the lack of a '/' at the end of the baseUrl.</p> <p>You will need to use a modified version of require.js to use the postfix solution. You can read more about this here: <a href="https://stackoverflow.com/a/21619359/1017787">https://stackoverflow.com/a/21619359/1017787</a></p> <p>Obviously in either case you will want to use some solution to replace <code>buildNumber</code> with some type of version number that changes with each release.</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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