Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[AssetMapper] Render a more precise importmap per page#60897

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
javiereguiluz wants to merge1 commit intosymfony:7.4
base:7.4
Choose a base branch
Loading
fromjaviereguiluz:better_importmaps

Conversation

javiereguiluz
Copy link
Member

QA
Branch?7.4
Bug fix?no
New feature?yes
Deprecations?no
Issues-
LicenseMIT

When a Twig template in a Symfony app uses AssetMapper like this:

{%blockimportmap %}    {{ importmap(['app','search','packages']) }}{%endblock %}

In the rendered HTML page, the<head> section will include this:

<!-- (1) Links to the CSS files used in the page --><linkrel="stylesheet"href="/assets/vendor/bootstrap/dist/css/bootstrap.min-FxLwN4-.css"><linkrel="stylesheet"href="/assets/styles/app-GZ-zm2A.css"><linkrel="stylesheet"href="/assets/@symfony/ux-live-component/live.min-ZJB0GOL.css"><linkrel="stylesheet"href="..."><!-- (2) Full importmap --><scripttype="importmap"data-turbo-track="reload">{"imports":{"app":"/assets/app-iodFN2G.js","bootstrap/js/src/offcanvas":"/assets/vendor/bootstrap/js/src/offcanvas-blSHiL2.js","/assets/stimulus.js":"/assets/stimulus-l2Vqto5.js","@symfony/stimulus-bundle":"/assets/@symfony/stimulus-bundle/loader-kxG46ja.js","...":"..."}}<!--(3)LinkstotheJSfilesusedinthepage--><linkrel="modulepreload"href="/assets/app-iodFN2G.js"><linkrel="modulepreload"href="/assets/vendor/bootstrap/js/src/offcanvas-blSHiL2.js"><linkrel="modulepreload"href="/assets/stimulus-l2Vqto5.js"><linkrel="modulepreload"href="/assets/@symfony/stimulus-bundle/loader-kxG46ja.js"><linkrel="modulepreload"href="..."><!-- (4) Imports (the same you used in importmap() call) --><scripttype="module"data-turbo-track="reload">import 'app';import 'search';import 'packages';</script>

(1), (3) and (4) are already perfect: they contain only what this page needs.

(2) is problematic IMO, because it discloses ALL the importmap entries of the application, including everything you'll never use in this page. In the past we've discussed about this and I want to bring this up again.

The problem is not about adding some unnecessary contents to the page(it's just a few bytes, so this is irrelevant). The problem is that the full importmap shows private things(think of the backend, etc.) and things that should not be public yet(new sections to be announced in the futurte, WIP sections, etc.). For these reasons, exposing all importmap entries in all pages is not OK for me.


In this PR, I made some minor changes that fix this. Now, theimportmap only includes the entries relevant for this page, hiding everything else.

It works in my tests, but I may have missed edge cases. Feedback welcome! Thanks!

@smnandre
Copy link
Member

i fear this will break all the lazy loading of Stimulus controllers

@smnandre
Copy link
Member

There are very valid reasons to have in the importmap assets you do not require to load 100% of the time on load

What you want to look at is thegetImportMapData method from theImportMapGenerator class.

But this would be a BC break and will require some form of flag.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Projects
None yet
Milestone
7.4
Development

Successfully merging this pull request may close these issues.

3 participants
@javiereguiluz@smnandre@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp