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

前端 未结 5 972
无人及你
无人及你 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:28

    Try to remove this part of code in routing_dev.yml when use_controller is false :

    _assetic:
        resource: .
        type:     assetic
    
    0 讨论(0)
  • 2021-02-04 05:28

    If you use assetic:dump, then you have to cache:clear -e dev

    "...if you run cache:clear on your production cache, it warms up the cache with debug mode on. If you try to dump assets afterwards, weird things might happen."

    i found it here: http://sftuts.com/using-assetic-in-symfony2-for-css-compression (4. paragraph)

    0 讨论(0)
  • 2021-02-04 05:37

    I have the same problem, working configuration is: comment out from routing_dev.yml:

    _assetic:
     resource: .
     type:     assetic
    

    set use_controller to false. After doing this I'm able to use assetic:dump and see working page.

    0 讨论(0)
  • 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:

    <script src="/app_dev.php/js/abcd123.js"></script>
    

    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.

    0 讨论(0)
  • 2021-02-04 05:46

    From the documentation

    Modify the dev config to avoid using the controller.

    # app/config/config_dev.yml
    assetic:
        use_controller: false
    

    Remove the route in routing_dev.yml to avoid side effect

    # app/config/routing_dev.yml
    _assetic:
        resource: .
        type:     assetic
    

    Automatically dump your css/less files every time you have a modification.

    php app/console assetic:dump --watch
    
    0 讨论(0)
提交回复
热议问题