Performance: Completely disable twig caching vs. disbling cache on modulars

Where will be the biggest impact on performance?

Let’s assume there is a start page of the site, which is a modular page and has 2 modulars using addInlineJS oder CSS.

To ensure that JS / CSS of the modular is rendered everytime, you can disable the caching of that modular.

what would be the best strategy to have maximum performance:

  1. disable twig caching completely
  2. disable cache in the modular
  3. disable cache in the page containing the modulars

Is there any best practice?

Do pages containing modulars get still cached even when some of the modulars are excluded from cache?

Obviously disabling cache means that more work has to be done on each viewing of a page. Module pages, ie, those that are included by the parent ‘modular’ page, are processed with their corresponding Twig template when the content() method is called. This is cached if cache is enabled. This is where dynamic things like form nonce codes get cached and don’t update when they need to.

Disabling cache on these module pages will ensure that the Twig is not cached, and the performance trade off is usually pretty small. However there is a better way! Use never_cache_twig: true in the page frontmatter will mean that the content is cached, but Twig is not processed before caching, and will just be run after. This is a better compromise as the page is cached, but only Twig has to run each time.