了解 Assetic 捆绑包
我无法理解 Assetic 捆绑包工作方式背后的原因,不幸的是官方文档并不太详细。
我只是看不出它处理静态路径和 url 的方式有什么好处。比如说,
{{ asset("bundles/mybundle/css/main.css") }}
被翻译成“/bundles/mybundle/css/main.css”。什么,只是在它前面加一个“/”?但我可以手动完成。我期望 Django 中至少有类似 STATIC_DIR 的东西,它指定所有静态文件所在的位置并用作静态根目录。
并
{% stylesheets '@MyBundle/Resources/public/css/main.css' %}
<link rel="stylesheet" href="{{ asset_url }}" type="text/css" media="all" />
{% endstylesheets %}
变成类似的东西
<link rel="stylesheet" href="/app_dev.php/css/618ab99_main_1.css" type="text/css" media="all" />
,但它不会为您的布局添加任何灵活性 - 当静态文件名更改时,您仍然必须编辑布局文件。而且您仍然需要手动编写 HTML“链接”标签。
考虑到您可以使用 Sf2 控制台在 web/ 目录中创建指向捆绑包公共文件夹的符号链接,我发现 Assetic 的工作方式有些晦涩难懂。我确信我错过了一些东西,所以我希望有人能为我解决这个问题。谢谢。
I'm having trouble understanding the reasons behind the way Assetic bundle works, and unfortunately the official documentation isn't too verbose.
I just fail to see any good in the way it deals with static paths and urls. Say,
{{ asset("bundles/mybundle/css/main.css") }}
gets translated into "/bundles/mybundle/css/main.css". What, just prepending it with a '/'? But I can do it manually. I expected at least something like STATIC_DIR in Django which specifies the place where all your static files live and serves as a static root directory.
And
{% stylesheets '@MyBundle/Resources/public/css/main.css' %}
<link rel="stylesheet" href="{{ asset_url }}" type="text/css" media="all" />
{% endstylesheets %}
becomes something like
<link rel="stylesheet" href="/app_dev.php/css/618ab99_main_1.css" type="text/css" media="all" />
But it doesn't add any flexibility to your layouts - you still have to edit your layout file when the static's filename get changed. And you still have to write HTML "link" tag manually.
Considering the fact you can use Sf2 console to create in a web/ dir a symlink to your bundle's public folder, I find the way Assetic works somewhat obscure. I'm sure that I miss something, so I hope someone can clear that out for me. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用一个脚本不会产生太大的效果。资产管理还有其他好处:
还有更多,您可以将它们组合起来以减少请求、过滤它、控制 url、缓存等。
资源
我喜欢:p
Using one script won't have much of an effect. Assetic management holds other benefits:
There's more as well, you can combine them for fewer requests, filter it, control the url, cache, etc.
Resource
I Like :p