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] If assets are served from a subdirectory or CDN, also adjust importmap keys#52519

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

Merged

Conversation

weaverryan
Copy link
Member

@weaverryanweaverryan commentedNov 9, 2023
edited
Loading

QA
Branch?6.4
Bug fix?yes
New feature?no
Deprecations?none
IssuesFixes#52520 (extra points for opening the PR before the issue was submitted? Anyone?)
LicenseMIT

Hi!

Subdirectories & CDN paths are tricky. Suppose you have:

// assets/app.jsimport './foo.js';

When we see that relative import tofoo.js, we automatically add an entry in theimportmap - e.g.:

"/assets/foo.js": "/assets/foo-abcd1234digest.js"

So, when the browser downloads/assets/app-abcd1234diegest.js, it follows the./foo.js relative path to resolve to/assets/foo.js. It then sees thatkey in theimportmap, and downloads the final file.

However, suppose you're under a subdirectory so that the browser downloads/subdir/assets/app-abcd1234diegest.js. In that case, it will resolve the relative import to/subdir/assets/foo.js. And so, thekey in the importmap also needs to have the/subdir inside of it.

Additionally, for a CDN, if the browser downloadshttps://cdn.com/assets/app.js, then it will resolve the import tohttps://cdn.com/assets/bar.js. If the key in the importmap is/assets/bar.js, that will NOT be used, as this is interpreted as the URL of the site - e.g.https://myfrontendsite.com/assets/bar.js. So even in this case, the key needs to be the fullhttps://cdn.com/assets/bar.js so that it's used.

I tested this locally on a subdirectory project as well as a CDN, where you setframework.asset.base_urls to somehttps://cdn.com/ type of URL.

Cheers!

nicolas-grekas reacted with laugh emoji
@hashbanged
Copy link
Contributor

Thank you,@weaverryan! Extra points:

extra-points

weaverryan reacted with laugh emoji

@fabpotfabpot merged commitfa4726f intosymfony:6.4Nov 10, 2023
This was referencedNov 10, 2023
@weaverryanweaverryan deleted the asset-mapper-importmap-base-url-key branchNovember 11, 2023 01:35
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
6.4
Development

Successfully merging this pull request may close these issues.

AssetMapper's importmap key is missing project prefix when deploying to subdirectory
4 participants
@weaverryan@hashbanged@fabpot@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp