Repository navigation
feat: preconnect to external image provider origins #2353
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
Open
luc122c
wants to merge
12
commits into
nuxt:main
Choose a base branch
from
luc122c:feat/preconnect-provider-urls
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+320
−4
Open
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
86e7931
feat: preconnect to external image provider origins
luc122c 1387d5a
docs: document the `preconnect` option
luc122c 0d0b027
fix: guard useRequestURL in usePreconnect, cover NuxtPicture
luc122c 33cc0cf
types: make CreateImageOptions.preconnect optional
luc122c 0762b01
docs: document preconnect on the NuxtPicture page
luc122c 1cce518
chore: clarify usePreconnect JSDoc
luc122c b223be0
test: cover preconnect crossorigin hint and distinct connection modes
luc122c 48cb2e6
feat: preconnect to a placeholder's origin too
luc122c 0840f68
chore: drop a redundant comment in NuxtImg preconnect block
luc122c dc697a5
fix: mirror the image's crossorigin in NuxtPicture preconnect hints
luc122c 1f3acfc
test: update bundle size snapshot
luc122c ec399b2
docs: clarify preconnect dedupe by connection mode
luc122c File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <template> | ||
| <div> | ||
| <nuxt-picture | ||
| provider="cloudinary" | ||
| src="/remote/nuxt-org/blog/going-full-static/main" | ||
| width="500" | ||
| height="500" | ||
| /> | ||
| </div> | ||
| </template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <template> | ||
| <div> | ||
| <nuxt-picture | ||
| provider="cloudinary" | ||
| src="/remote/nuxt-org/blog/going-full-static/main" | ||
| width="100" | ||
| height="100" | ||
| :img-attrs="{ crossorigin: 'use-credentials' }" | ||
| /> | ||
| <nuxt-picture | ||
| provider="cloudinary" | ||
| src="/remote/nuxt-org/blog/going-full-static/main" | ||
| width="120" | ||
| height="120" | ||
| :img-attrs="{ crossorigin: '' }" | ||
| /> | ||
| </div> | ||
| </template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <template> | ||
| <div> | ||
| <nuxt-img | ||
| provider="cloudinary" | ||
| src="/remote/nuxt-org/blog/going-full-static/main" | ||
| width="100" | ||
| height="100" | ||
| crossorigin="anonymous" | ||
| /> | ||
| <nuxt-img | ||
| provider="cloudinary" | ||
| src="/remote/nuxt-org/blog/going-full-static/main" | ||
| width="120" | ||
| height="120" | ||
| /> | ||
| <nuxt-img | ||
| provider="cloudinary" | ||
| src="/remote/nuxt-org/blog/going-full-static/main" | ||
| width="140" | ||
| height="140" | ||
| crossorigin="anonymous" | ||
| /> | ||
| </div> | ||
| </template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <template> | ||
| <div> | ||
| <nuxt-img | ||
| src="/images/nuxt.png" | ||
| width="100" | ||
| height="100" | ||
| placeholder="https://res.cloudinary.com/nuxt/image/upload/images/nuxt.png" | ||
| /> | ||
| </div> | ||
| </template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /** | ||
| * Resolve the origin a cross-origin image URL should be preconnected to. | ||
| * | ||
| * Returns `undefined` when the URL is empty, relative, same-origin as | ||
| * `baseHref`, not parseable, or not an `http(s)` URL (so `data:`, `blob:` | ||
| * and other schemes are ignored). | ||
| */ | ||
| export function resolvePreconnectOrigin(url: string | undefined, baseHref: string): string | undefined { | ||
| if (!url) { | ||
| return | ||
| } | ||
|
|
||
| let base: URL | ||
| let resolved: URL | ||
| try { | ||
| base = new URL(baseHref) | ||
| resolved = new URL(url, base) | ||
| } | ||
| catch { | ||
| return | ||
| } | ||
|
|
||
| if (resolved.protocol !== 'http:' && resolved.protocol !== 'https:') { | ||
| return | ||
| } | ||
|
|
||
| if (resolved.origin === base.origin) { | ||
| return | ||
| } | ||
|
|
||
| return resolved.origin | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.