Symfony2 共享 CSS 和 JS 资产去哪里了,最佳实践明智吗? [英] Where do Symfony2 shared CSS and JS assets go, best practice wise?

查看:23
本文介绍了Symfony2 共享 CSS 和 JS 资产去哪里了,最佳实践明智吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通常将我的 JS 和 CSS Assetic 资产放在 DefaultBundle 中,但我认为将它们放在 app/Resources/public/(js|css) 文件夹中的最佳位置.

I normally place my JS and CSS Assetic assets inside a DefaultBundle, but I suppose the best place to put them would be in the app/Resources/public/(js|css) folders.

此外,参考我们使用的资产:

Also, to reference assets we use:

{% javascripts filter="" output="js/core.js" debug=true
    "@DefaultBundle/Resources/public/js/jquery-1.6.2.js" %}
    <script src="{{ asset_url }}" type="text/javascript"></script>
{% endjavascripts %}

如何在 app/Resources/public/... 中引用共享资产(如 jQuery 和 CSS 重置样式表)?

How do I go about referencing shared assets like jQuery and my CSS reset stylesheets in app/Resources/public/...?

推荐答案

是的,不将库放在 Bundle 中是一个不错的选择

Yes it's a good choice to not put libraries inside a Bundle

见这里:http://symfony.com/doc/current/cookbook/bundles/best_practices.html#vendors

捆绑包不应嵌入用 JavaScript、CSS 或任何其他语言编写的第三方库.

A bundle should not embed third-party libraries written in JavaScript, CSS, or any other language.


我建议您将 jquery 和重置文件放在类似以下内容的位置:app/Resources/public/js/jquery.min.js 并使用以下内容更改您的代码:


What i suggest you, is to put you jquery and reset files under something like: app/Resources/public/js/jquery.min.js and to change your code with something like:

{% javascripts filter="" output="js/core.js" debug=true
    "../app/Resources/public/js/jquery-1.6.2.js" %}
    <script src="{{ asset_url }}" type="text/javascript"></script>
{% endjavascripts %}

我希望这对你有用.

编辑:将答案编辑为 https://stackoverflow.com/a/9237004/505836,谢谢大卫.

EDIT: Edited answer to be like https://stackoverflow.com/a/9237004/505836, thanks David.

这篇关于Symfony2 共享 CSS 和 JS 资产去哪里了,最佳实践明智吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆