Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#13612 closed defect (fixed)

cache problem with require

Reported by: liucougar Owned by: Rawld Gill
Priority: high Milestone: 1.7
Component: Loader Version: 1.7.0b1
Keywords: Cc:
Blocked By: Blocking:


save the following content into test.html under dojo dir

<script src="../dojo/dojo.js" data-dojo-config="async:1"></script>
require(["dojo/text"], function(){
        require(['dojo/text!dojo/resources/blank.html'], function(template){
                console.log('template', template);


load it in browser, actual result: console shows the real content of blank.html

expected result: 'ok' should be the template

NOTE: if the outer require(["dojo/text"]... is removed, then this works properly. or if require({cache:{'url... is moved out of the outer require, it works as expected.

don't know whether this is intended or not

Change History (6)

comment:1 Changed 10 years ago by liucougar

Component: GeneralLoader
Owner: set to Rawld Gill

comment:2 Changed 10 years ago by Rawld Gill

Status: newassigned

comment:3 Changed 10 years ago by Rawld Gill

Resolution: fixed
Status: assignedclosed

In [26704]:

added feature to immediately consume loader cache; fixes #13612; !strict; thanks, great find cougar

comment:4 Changed 10 years ago by Rawld Gill

Hi Cougar!

Thanks for the find.

The cache is not immediately consumed because it's contents may be with respect to another module that is mapped via packageMap.

Inserting into the loader cache is cached until the next module is loaded, at which point the cached, cached modules can be consumed and entered into the loader cache, possibly remapping them to another namespace as per the packageMap. In the example above, there is no module loaded (the plugin is already loaded), so the cached module is not actually in the cache and available for the plugin to retrieve. Prior to [26704], it was possible to force the cached, cached modules to be consumed by inserting an empty cache hash like this:


However, this seemed to crufty, so I've added the cache signal "*noref" that says the cache modules provided is not subject to remapping and should be immediately consumed. Therefore, the example can be expressed as follows:

require({cache:{"*noref":1, 'url:dojo/resources/blank.html':'ok'}});

...and it will work in all cases.

comment:5 Changed 10 years ago by Rawld Gill

In [26705]:

improved [26704]; refs #13612; !strict

comment:6 Changed 10 years ago by liucougar

thanks for the explanation and fix

Note: See TracTickets for help on using tickets.