How to make Symfony2 to load CSS, JS files directly and not via PHP?

前端 未结 5 984
无人及你
无人及你 2021-02-04 04:55

OLD QUESTION, SEE BELOW FOR THE UPDATED VERSION

My development environment is not the fastest. I takes roughly 500ms per PHP request. It\'s starting to

5条回答
  •  旧巷少年郎
    2021-02-04 05:43

    Symfony documentation is always the first place where to start look: How to Use Assetic for Asset Management

    In the prod environment, your JS and CSS files are represented by a single tag each. In other words, instead of seeing each JavaScript file you're including in your source, you'll likely just see something like this:

    
    

    Moreover, that file does not actually exist, nor is it dynamically rendered by Symfony (as the asset files are in the dev environment). This is on purpose - letting Symfony generate these files dynamically in a production environment is just too slow.

    Instead, each time you use your app in the prod environment (and therefore, each time you deploy), you should run the following task:

    php app/console assetic:dump --env=prod --no-debug
    

    This will physically generate and write each file that you need (e.g. /js/abcd123.js). If you update any of your assets, you'll need to run this again to regenerate the file.

提交回复
热议问题