Dojo build queries with pre-configured templates

I'm hopelessly trying to make the Dijit template Dojo builds attachment functionality for my AMD project with no luck ...

The specific problem is not the development of the HTML templates themselves, but the fact that they are still being requested with Ajax (XHR) after a successful attachment.

Templates are embedded as follows:

 "url:app/widgets/Example/templates/example.html": '<div>\n\tHello World!</div>' 

The Dijit widget itself after assembly defines such patterns:

 define("dojo/_base/declare,dijit/_Widget,dojo/text!./templates/example.html".split(","), function (f, g, d) { return f("MyApp.Example", [g], { templateString: d, }); }); 

I tried to build with:

  • shrink / close optimizer
  • relative / absolute paths
  • using the old cache() method
  • using the templatePath property

but even after a successful build (0 errors and a few warnings) where the templates were built in, Dojo / Dijit still makes Ajax requests to these resources.

Here is my build profile:

 var profile = { basePath: '../src/', action: 'release', cssOptimize: 'comments', mini: true, optimize: 'closure', layerOptimize: 'closure', stripConsole: 'all', selectorEngine: 'acme', internStrings: true, internStringsSkipList: false, packages: [ 'dojo', 'dijit', 'dojox', 'app' ], layers: { 'dojo/dojo': { include: [ 'app/run' ], boot: true, customBase: true }, }, staticHasFeatures: { 'dojo-trace-api': 0, 'dojo-log-api': 0, 'dojo-publish-privates': 0, 'dojo-sync-loader': 0, 'dojo-xhr-factory': 0, 'dojo-test-sniff': 0 } }; 

Because of this problem, my application is completely unusable because there are so many files to download separately (browsers have a limit on the number of concurrent connections).

Thank you in advance!

UPDATE:

Two lines loading dojo.js and run.js into my index.html :

 <script data-dojo-config='async: 1, tlmSiblingOfDojo: 0, isDebug: 1' src='/public/dojo/dojo.js'></script> <script src='/public/app-desktop/run.js'></script> 

Here is the new build-profile :

 var profile = { basePath: '../src/', action: 'release', cssOptimize: 'comments', mini: true, internStrings: true, optimize: 'closure', layerOptimize: 'closure', stripConsole: 'all', selectorEngine: 'acme', packages : [ 'dojo', 'dijit', 'app-desktop' ], layers: { 'dojo/dojo': { include: [ 'dojo/request/xhr', 'dojo/i18n', 'dojo/domReady', 'app-desktop/main' ], boot: true, customBase: true } }, staticHasFeatures: { 'dojo-trace-api': 0, 'dojo-log-api': 0, 'dojo-publish-privates': 0, 'dojo-sync-loader': 0, 'dojo-xhr-factory': 0, 'dojo-test-sniff': 0 } }; 

My new run.js file:

 require({ async: 1, isDebug: 1, baseUrl: '/public', packages: [ 'dojo', 'dijit', 'dojox', 'saga', 'historyjs', 'wysihtml5', 'app-shared', 'jquery', 'jcrop', 'introjs', 'app-desktop' ], deps: [ 'app-desktop/main', 'dojo/domReady!' ], callback: function (Main) { debugger; var main = new Main(); debugger; main.init(); } }); 

and my main.js file looks like this:

 define([ 'dojo/_base/declare', 'app-desktop/widgets/Application', 'app-desktop/config/Config', 'saga/utils/Prototyping', 'dojo/window', 'dojo/domReady!' ], function (declare, Application, ConfigClass, Prototyping, win) { return declare([], { init: function() { // ... other stuff application = new Application(); application.placeAt(document.body); // ... some more stuff } }); }); 

The following error appears in build-mode :

 GET http://localhost:4000/app-desktop/run.js 404 (Not Found) 

which is strange because it means that the build process made it so that Dojo has an external dependency and not the built-in dojoConfig variable in the dojoConfig file.

Files are requested in normal-mode , but the application is never created.

In both cases, none of the two debuggers installed in the run.js file started, which means that the callback method was never called for any reason.

Thank you for your help!

+4
source share
2 answers

I printed the values โ€‹โ€‹of requireCacheUrl and require.cache for the console in the load () method of dojo / text.js. At least in my case, the keys of my templates in the cache are different from the search keys on one leading slash.

For example, I have "dojo/text!./templates/Address.html" in my widgets. It is present with the url:/app/view/templates/Address.html in the cache, but it is searched as url:app/view/templates/Address.html , causing a cache miss and xhr request.

With an additional slash in dojo / text.js (line 183 for version 1.9.1), it seems to work (the line will look like requireCacheUrl = "url:/" + url ).

I do not know what errors may occur in this โ€œfixโ€. Therefore, it is probably worth reporting the dojo problem to people.

UPD: I see you have already reported this problem. Here is the link: https://bugs.dojotoolkit.org/ticket/17458 .

UPD: Do not use the hack described above. It was only an attempt to exacerbate the problem. The real problem in my project was the packages and settings of baseUrl. I originally created my project based on https://github.com/csnover/dojo-boilerplate . Then they fixed it as a non-standard sample .

0
source

This sounds like https://bugs.dojotoolkit.org/ticket/17141 . If so, you just need to upgrade to Dojo 1.9.1.

0
source

Source: https://habr.com/ru/post/1502212/


All Articles