mirror of
https://github.com/withastro/astro.git
synced 2025-02-17 22:44:24 -05:00
fix(astro): Prevent prefetching of same urls with different hashes (#11713)
* fix(astro): prevent prefetching of the same urls with different hashes * add changeset * Update packages/astro/src/prefetch/index.ts Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com> * Update .changeset/nasty-ladybugs-whisper.md Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com> --------- Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
This commit is contained in:
parent
6fcaab84de
commit
497324c4e8
2 changed files with 8 additions and 0 deletions
5
.changeset/nasty-ladybugs-whisper.md
Normal file
5
.changeset/nasty-ladybugs-whisper.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Prevents prefetching of the same urls with different hashes.
|
|
@ -215,6 +215,9 @@ export interface PrefetchOptions {
|
||||||
* @param opts Additional options for prefetching.
|
* @param opts Additional options for prefetching.
|
||||||
*/
|
*/
|
||||||
export function prefetch(url: string, opts?: PrefetchOptions) {
|
export function prefetch(url: string, opts?: PrefetchOptions) {
|
||||||
|
// Remove url hash to avoid prefetching the same URL multiple times
|
||||||
|
url = url.replace(/#.*/, '');
|
||||||
|
|
||||||
const ignoreSlowConnection = opts?.ignoreSlowConnection ?? false;
|
const ignoreSlowConnection = opts?.ignoreSlowConnection ?? false;
|
||||||
if (!canPrefetchUrl(url, ignoreSlowConnection)) return;
|
if (!canPrefetchUrl(url, ignoreSlowConnection)) return;
|
||||||
prefetchedUrls.add(url);
|
prefetchedUrls.add(url);
|
||||||
|
|
Loading…
Add table
Reference in a new issue