javascript - How to Use Assetic for requireJs - Stack Overflow

I am trying to use require.js in synfony2 project.Here the code in the main twig file:<script data-m

I am trying to use require.js in synfony2 project.

Here the code in the main twig file:

<script 
        data-main="{{ asset('bundles/web/js/main.js') }}" 
        src="{{ asset('vendor/js/require.js') }}">
</script>

The file vendor/js/require.js is correctly loaded but for the file bundles/web/js/main.js I get the message:

Uncaught Error: Load timeout for modules: mainApp.js?201205021855 .html#timeout

I am using RequireJS 1.0.8. Any idea how to fix the problem? Thanks.


If I look to the source page it looks like:

<script 
      data-main="/~myName/myProject/web/bundles/web/js/main.js?101205021855"       
      src="/~myName/myProject/web/vendor/js/require.js?101205021855">
</script>

So the paths are rights, but on javascript console I get the following message:

GET http://localhost/~myName/myProject/web/app_dev.php/main.js?201205021855 404 (Not Found)

I am trying to use require.js in synfony2 project.

Here the code in the main twig file:

<script 
        data-main="{{ asset('bundles/web/js/main.js') }}" 
        src="{{ asset('vendor/js/require.js') }}">
</script>

The file vendor/js/require.js is correctly loaded but for the file bundles/web/js/main.js I get the message:

Uncaught Error: Load timeout for modules: mainApp.js?201205021855 http://requirejs/docs/errors.html#timeout

I am using RequireJS 1.0.8. Any idea how to fix the problem? Thanks.


If I look to the source page it looks like:

<script 
      data-main="/~myName/myProject/web/bundles/web/js/main.js?101205021855"       
      src="/~myName/myProject/web/vendor/js/require.js?101205021855">
</script>

So the paths are rights, but on javascript console I get the following message:

GET http://localhost/~myName/myProject/web/app_dev.php/main.js?201205021855 404 (Not Found)

Share Improve this question edited Sep 20, 2012 at 19:37 j0k 22.8k28 gold badges81 silver badges90 bronze badges asked May 9, 2012 at 20:01 underscore666underscore666 1,7395 gold badges24 silver badges38 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

Adding to @dgabriel response. You can do it using slice filter,

<script 
        data-main="{{ asset('bundles/web/js/main.js') | slice(0, -3) }}" 
        src="{{ asset('vendor/js/require.js') }}">
</script>
  1. Make sure to leave off the '.js' file extension from your assets. It should be data-main="{{ asset('bundles/web/js/main') }}"

  2. Make sure your path to the file is correct.

  3. Make sure there are no javascript errors in main.js

That 404 looks like it's ing as a result of 'main' being required somewhere else in your application - it doesn't match the path in your data-main. In that case, it's most likely an issue with your baseUrl or paths config (both of which are different ways to tell RequireJS where your modules are located). In your example, your baseUrl would need to be '/~myName/myProject/web/bundles/web/js'.

You may want to try using https://github./hearsayit/HearsayRequireJSBundle. It handles those configuration details for you automatically, and integrates nicely with Assetic.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745491945a4630023.html

相关推荐

  • javascript - How to Use Assetic for requireJs - Stack Overflow

    I am trying to use require.js in synfony2 project.Here the code in the main twig file:<script data-m

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信