I'm trying to work with requirejs and text plugin and I have weird problem.
I have two web servers:
- localhost:3000 - act as CDN and has all the static files: js, images, css and templates
- localhost:3001 - server - act as REST server and serve only one file, the main.html file
The main.html file loads all the js files from the second server using the following line:
<script data-main="http://localhost:3000/js/main"
src="http://localhost:3000/lib/require-jquery.js"></script>
For some reason, when using the requirejs text plugin, he adds to the templates ".js"
suffix when navigating to localhost:3001
I'm using the following syntax:
define ['jquery','backbone','underscore','models/model','text!templates/main.html',
'views/navigation', 'views/player', 'views/content', 'views/header']
when I navigate to localhost:3000 it works fine.
Can you think of any reason that the text plugin would have problems serving text files from a remote server (for example, CDN server)?
I've had trouble with the text plugin when working across domains and perhaps your two localhost servers are hitting this too.
In the web inspector I saw that require.js was trying to fetch things like
some-content.html.js
instead ofsome-content.html
.Are you running this code in development mode or building into a production set? When you bundle everything up the text plugin shouldn't have this same cross-domain trouble.
Here's the API documentation part that tipped me off (from http://requirejs.org/docs/api.html):
Here's an article that helped me work around this for browsers that support CORS: