Problem/Motivation

Is there any reason why development.services.yml does not disable TWIG cache by default? Every core update overrides this file with the default one. Themers routinely set those 3 lines, but this is a repetitive task. And the file loads only when settings.local.php is included, so it will not cause any problems on production sites.

Proposed resolution

Add the twig.config related lines to development.services.yml, under parameters: key:

  twig.config:
    debug: true
    auto_reload: true
    cache: false

So the whole file will look like this:

# Local development services.
#
# To activate this feature, follow the instructions at the top of the
# 'example.settings.local.php' file, which sits next to this file.
parameters:
  http.response.debug_cacheability_headers: true
  twig.config:
    debug: true
    auto_reload: true
    cache: false
services:
  cache.backend.null:
    class: Drupal\Core\Cache\NullBackendFactory

Comments

gpap created an issue. See original summary.

gpap’s picture

Issue summary: View changes
gpap’s picture

Thew’s picture

I agree with you. I need to add it manually every time I get the fresh installation.

Maybe add the twig parameters to development.services.yml and comment it out.
If themers want it, he can remove the comment, like Disable the render cache in example.settings.local.php.

# Local development services.
#
# To activate this feature, follow the instructions at the top of the
# 'example.settings.local.php' file, which sits next to this file.
parameters:
  http.response.debug_cacheability_headers: true
  # twig.config:
  #   debug: true
  #   auto_reload: true
  #   cache: false
services:
  cache.backend.null:
    class: Drupal\Core\Cache\NullBackendFactory

However, if my thought is right, you can only set debug: true. The auto_reload and cache will automatically follow the debug parameter. See Debugging compiled Twig templates

binoli.addweb’s picture

Status: Active » Needs review
FileSize
492 bytes

Please apply disable_twig_cache_by-2839709-5.patch.

Cottser’s picture

Status: Needs review » Needs work

Thanks for the suggestion. I'm not sure if this was discussed before, there may have been a reason to not include it. Enabling twig debug can have side effects, because of the HTML comments added. For example, #2656728: Twig split in debug mode. Enabling auto_reload for development should be safe though.

Disabling twig cache in my experience has no benefits, only downsides:

  1. Harder to debug compiled templates because they aren't saved to disk.
  2. Templates need to be compiled each time no matter what, slowing things down.

See https://github.com/hechoendrupal/drupal-console/pull/1310 from the Drupal Console project where something similar came up.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

joelpittet’s picture

I'm on board with the this except cache like @Cottser mentioned in #6. And with debug on, auto_reload is on by default so doesn't need to be added, though that's not too much a concern.

Would you mind removing those from the patch @binoli.addweb?