Eugene
Eugene

Reputation: 1535

Requirejs doesn't load when site is in subfolder

I have the following site configuration

index.html
scripts/
        require.js
        modules/
                mymodule.js

in index.html I have

<script src="/Scripts/require.js" data-main="/Scripts/Modules/mymodule.js"></script>

<script>
       $(document).ready(function () {
           require(['mymodule'], function (mymodule) {...} 
       }
</script>

Locally it works perfect, but on server I have IIS with this site in subfolder like http://domainname.com/MySite-QA/ and requirejs tries to load data not from http://domainname.com/MySite-QA/scripts/modules/mymodule.js but from http://domainname.com/scripts/modules/mymodule.js and fails.

How can I make requirejs work with sites in top directory and in subdirectory??

Upvotes: 0

Views: 58

Answers (1)

jonasnas
jonasnas

Reputation: 3580

You could use relative URLs rather than absolute (with / in front of the script):

<script src="Scripts/require.js" data-main="Scripts/Modules/mymodule.js"></script>

But then this path will have to change if html file is moved to some other place since it is relative to it's location

Upvotes: 1

Related Questions