I downloaded the dojo toolkit and open the dijit/themes/themeTester.html. The dojo can't work. I have to copy the toolkit to the webapp directory of my web serve开发者_开发知识库r. Then I access the same html through HTTP. The dojo works.
During the development, do I have to always deploy a page to web server for testing?
Thanks.
This behavior is not Dojo-specific. Some browsers (Firefox comes to mind) prohibit web pages loaded directly from file system to load resources outside of their home directory for security reasons.
Example: your web page is in /home/bob/page.html
. It can include following resources:
bob.js
(effective path:/home/bob/bob.js
)./sam.js
(/home/bob/sam.js
)abc/spot.js
(/home/bob/abc/spot.js
)- and so on
It cannot load following resources (even if they exist):
../bob.js
(/home/bob.js
)/home/tom/script.js
../tom/script.js
(/home/tom/script.js
)
Theoretically you can go into Firefox guts and turn this "feature" off, but you may encounter other problems:
- In some cases XHR works funny from file system. Web servers send MIME headers with files, while file system doesn't provide this service, and XHR is forced to guess. Sometimes it guesses wrong.
- While Dojo doesn't need any server-side code, its tests may use PHP to emulate server-side data stores and other things. When running from file system, those PHP files are usually served as is, instead of being executed.
Other than that you should be able to run any web application directly from file system. Just make sure that the whole app is inside one folder, all HTML pages are in the top folder (or in subfolders, but do not use anything "above" them), avoid absolute paths, and "go up" symbols (..
) in paths that take you outside of the main folder (even temporarily), and always test your XHR responses.
精彩评论