I’ve been working with Require.js and Backbone.js and al. I’ve been trying to make a simple todo application which I run by double-clicking index.html from my desktop and showing it in the browser and using it.
However, when fetching a template by Require.js, it’s giving me the following error:
XMLHttpRequest cannot load file:///C:/bada/js/templates/headerTemplate.html. Cross origin requests are only supported for HTTP.
I know this is happening because I’m not doing the request from a server. I know in Chrome, this error can be suppressed by using some parameters when launching Chrome, but I also intend to use this app on my mobile phone, by runnning index.html locally.
Is there anyway to prevent this error from happening and having the app work ok?
Short answer: no.
Longer answer: look into application caching.
Do NOT do it before your app is done being built. But after it’s built, if you set up an offline cache and take advantage of
localStorage(if needed), it should run on most respectable phones/tablets/laptops/PCs.But like I said, DON’T set up your cache manifest until after you’re ready to freeze all of your file data as it is.
It does a really good job of caching data, which is great… …but if you make changes to any file, it becomes REALLY painful to invalidate the cache to download the latest version, to reset the cache using the new stuff…
…and if you like to hit CTRL+S every 5 minutes, like me, just to be safe…
…then you’re in for a headache if you want to see those micro-changes in action.