Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to set baseurl dynamicly in require.js?

I am building an application on Pi-engine (a php application engine based on zend framework 2).

In my application the javascript file path depends on the application name, while the application name is pickded by installer.

For example the url of require.js would be:

http://my.site.name/asset/module-{module_name}/script/js/require.js

module_name changes according to what name the application is given.

I know I can put path in 'data-main' attribute in backend like:

<script data-main="/asset/module-{module_name}/script/" src="/asset/module-{module_name}/script/js/require.js"></script>

But I want to know is there any way to set baseurl dynamicly using javascript so that I don't need to touch the backend.

like image 859
user1522830 Avatar asked Apr 10 '13 08:04

user1522830


1 Answers

http://requirejs.org/docs/api.html#config

Also, you can define the config object as the global variable require before require.js is loaded, and have the values applied automatically. This example specifies some dependencies to load as soon as require.js defines require():

<script>
    var require = {
        baseUrl: generateBaseUrl()
    };
</script>
<script src="scripts/require.js"></script>
like image 191
Paul Grime Avatar answered Oct 06 '22 01:10

Paul Grime