craftcms / craftcms/cms

[4.x]: Css and JS not loading if we use {% cahe %}

Open
#17,182 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug craft4
Dominant language
PHP
Stars
3.6k
Forks
705
Avg merge
1d 5h
Merged PRs (30d)
134

Description

What happened?
Description

I have a code like this

{% cache %}
<!DOCTYPE html>
{% set htmlAttrs = {
    lang: craft.app.language,
    class:
    [
        'h-full',
    ]
} %}

<html {{ attr(htmlAttrs) }}>
<head>
</head>

    <body class="min-h-full h-auto text-base font-sans">
        {# Added Hook for after body start #}
        {% hook 'after-body-start' %}

{% include "_/includes/cookie-consent" %}
</body>
</html>
{% endcache %}

it needed to load assets but it doesnt. if i turn off cache from config/general.php or remove {% cache %} code from template, assets do load.

Happens in latest version of craft cms v4.15.2

Craft CMS version

4.15.2

PHP version

8.2

Operating system and version

MacOs 15.1.1 (24B91)

Database type and version

mysql Ver 8.0.40 for macos15.1 on arm64 (Homebrew)

Image driver and version

No response

Installed plugins and versions

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the provided template with the cache tag on Craft CMS 4.15.2, comparing asset loading with caching enabled and disabled. Inspect the cache behavior around the template and the config/general.php setting; done means CSS and JavaScript assets load while the cache tag remains enabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.