简体   繁体   English

Symfony2资产变更

[英]Symfony2 asset changes

So it's my understanding that in the symfony dev environment assets are generated on page load through the controller if use_controller is set to true. 因此,据我了解,如果将use_controller设置为true,则在symfony开发环境中会通过控制器在页面加载时生成资产。

This is however time consuming, and pages load much faster with it set to true. 但是,这很耗时,并且设置为true时页面加载会快得多。 I use less and javascript and I do not want to dump my assets every change, as I'm constantly changing these files and viewing them. 我使用的JavaScript较少,并且我不想每次更改都转储我的资产,因为我一直在更改这些文件并进行查看。

I also don't want to wait the 20 seconds it takes to generate all the assets every page load. 我也不想等待花费20秒的时间来生成每个页面加载的所有资产。

Using assetic:dump --watch breaks my less files every time so it's pretty much useless for me, but sounds ideal. 使用assetic:dump --watch每次都会中断较少的文件,因此对我来说几乎没有用,但是听起来很理想。 Only update what I update, great let's do that, then I can set use_controller to false and have minimal page load and have my assets updated. 只更新我更新的内容,好吧,那么,我可以将use_controller设置为false,以最小的页面加载并更新我的资产。

Where is the balance here? 这里的余额在哪里?

How can I have a fast dev env while being able to work on my assets? 在能够处理我的资产的同时如何获得快速的开发环境?

Or 要么

How can I get assetic:dump --watch to not break my css/less, as this sounds like the ideal solution. 我如何获得资产:转储-观看时不要破坏CSS / less,因为这听起来像是理想的解决方案。 Does anyone else use less and assetic:dump --watch? 还有谁使用更少的资产吗?

Any comments, answers, articles or advice is greatly appreciated and I know similar questions have been asked here, most pointing out to use assetic:dump --watch, which does not work for me. 任何评论,答案,文章或建议都将不胜感激,并且我知道在这里提出了类似的问题,其中大多数指出是使用assetic:dump --watch,这对我不起作用。

I don't know for others, but the fastest way for me to get around this issue is to have the assets stored in the web/ directory. 我对其他人不了解,但是解决该问题的最快方法是将资产存储在web/目录中。 I know it's probably not the best way but after a couple of days searching through the net I just decided I was wasting my time. 我知道这可能不是最好的方法,但是经过几天的搜索,我才决定浪费时间。

So depending on the project, my assets go into the web/ path. 因此,根据项目的不同,我的资产会进入web/路径。 If the project is huge and has many separate bundles, I might have it both ways: 如果项目规模巨大并且有很多单独的捆绑包,那么我可能会同时使用两种方式:

  1. Store my assets in the proper MyCompany/MyBundle/Resources/public/(images|js|css|images) path 将我的资产存储在正确的MyCompany/MyBundle/Resources/public/(images|js|css|images)路径中
  2. In case I have ongoing work on a specific asset(s), I temporarily change the links to point to web/mystyle.css 如果我正在处理特定资产,请暂时更改链接以指向web/mystyle.css
  3. I create web/mystyle.css , do my work and then copy/paste the changes back to MyCompany/MyBundle/Resources/public/css/mystyle.scss 我创建了web/mystyle.css ,做我的工作,然后将更改复制/粘贴回MyCompany/MyBundle/Resources/public/css/mystyle.scss

This saves me a lot of page load time. 这为我节省了很多page load时间。 Usually my load time was around 4-5 seconds, which dropped to between 0.4s and 0.7s by simply placing the assets into the web/ path. 通常,我的加载时间约为4-5秒,只需将资产放入web/路径,即可将其降至0.4s至0.7s。 Again, I'm not pretending for this to be the best way to go, but it does the work for me. 再说一次,我并不假装这是最好的方法,但这确实对我有用。 If anybody has a better way, please let me know - I would be interested as well. 如果有人有更好的方法,请让我知道-我也会有兴趣。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM