Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Add event to allow manage $resources. #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kszymukowicz
Copy link

hi

I have an edge case that I do not need all resources produced by TYPO3 to have http2 header and the current way the b13/http2 works is that it adds all resources to http2.

Below there is real example of this edge case.

An external TYPO3 extension is adding a JS which is not needed at first loading because user will first need to give cookie consent before using this JS. Therefore there is no need to load this JS file early with http2. In fact there is even no need to load it at once with async because it will be never used without cookie consent. We want to load this JS when some JS condition is meet hasAcceptedCookieConsent()

So what we would need is only a url of JS asset that can be used later in JS to load this extension JS. To achieve this an assets is declared with some special type - for example like text/html/consent.

The JS declaration described above could have following declaration:

    modalbox = EXT:modalbox/Resources/Public/Js/modalbox-init.js
    modalbox {
      excludeFromConcatenation = 1
      disableCompression = 1
      type = text/html/consent
    }

and inline JS in like that:

if (hasAcceptedCookieConsent()) {
 const scripts = document.querySelectorAll('script[type="text/html/consent"]');
 scripts.forEach(script => {
              script.type = 'text/javascript';
              const newScript = document.createElement('script');
              newScript.src = script.src;
              document.head.appendChild(newScript);
        });
}

Unfortunately with current b31/http2 behaviour modalbox.js is added to early link download and downloaded even if it is not needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant