旧问题,请参见下面的更新版本
我的开发环境不是最快的。每个PHP请求大约需要500ms,这已经成为Symfony2资源文件的问题,因为每个资源文件都是通过Symfony的内部控制器请求的:
http://localhost/myproj/app_dev.php/js/bb8690a_part_4_myJavaScriptFile_2.js
可以看到,这些文件是通过Symfony框架而不是直接加载的。由于我开始有超过20个文件要加载,乘以500毫秒,导致页面加载非常缓慢。我想直接加载文件,但我不知道该怎么做。
这是config.yml
的一部分:
# Assetic Configuration
assetic:
debug: %kernel.debug%
use_controller: false
# java: /usr/bin/java
filters:
cssrewrite: ~
我曾以为将use_controller
设为false
就可以解决问题,但事实并非如此。
有没有一种方法可以直接处理这些资源的加载?
更新:
现在它尝试使用以下URL:
http://localhost/myproj/_controller/js/bb8690a_part_4_myJavaScriptFile_2.js
我已经为开发和通用配置设置了use_controller
为false
。我该如何去掉URL中的_controller
部分?
编辑:如果我清除缓存、运行assetic:dump
并将use_controller
设置为false
,那么重新加载后会出现Cannot load resource "."
的错误。我无法解决这个问题,除非我暂时启用use_controller
进行一次页面加载。之后,我禁用它并重新加载,现在它从包含_controller
的无效URL请求。
它似乎在生产环境中也能正常工作,但在开发环境中则不行。奇怪。
模板代码:
{% stylesheets filter="cssrewrite"
'bundles/outotecofil/css/reset.css'
'bundles/outotecofil/css/*'
output='css/dist/dist.css'
%}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
{% javascripts
'@OutotecCommonBundle/Resources/public/js/jquery-1.6.2.min.js'
'@OutotecCommonBundle/Resources/public/js/jquery-ui-1.8.16.custom.min.js'
'@OutotecCommonBundle/Resources/public/js/chosen.jquery.min.js'
'@OutotecCommonBundle/Resources/public/js/widget/*'
'@OutotecOFILBundle/Resources/public/js/OFILDependencyManager.js'
'@OutotecOFILBundle/Resources/public/js/widget/*'
'@OutotecOFILBundle/Resources/public/js/plant-scope.js'
output='js/dist/dist.js'
%}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
需要非常清楚的是:在没有app_dev.php(即在生产模式下),它可以正常运行。只有在开发模式下,它才无法正常工作并引发此“无法加载资源”错误,除非我先为一个请求启用use_controller
,然后我可以禁用它并重新加载,尽管URL将包含_controller /
。