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

🐛 BUG: Automatic Link header generation does not take into account base URL #7181

Open
davidlj95 opened this issue Nov 6, 2024 · 0 comments
Labels
bug Something that isn't working

Comments

@davidlj95
Copy link

davidlj95 commented Nov 6, 2024

Which Cloudflare product(s) does this pertain to?

Pages

What version(s) of the tool(s) are you using?

3.84.1 (Wrangler)

What version of Node are you using?

No response

What operating system and version are you using?

N/A

Describe the Bug

Observed behavior

Let's consider an index.html page within a subdirectory /subdir that contains:

  • A <base href="/">: to provide / as base URL for all links in the document
  • A <link rel="modulepreload" href="module.js">: to preload the module.js

The page is served through Cloudflare Pages.

Thanks to automatic Link header generation the Link response header is added to the response as expected.

The response contains the following Link response header:

Link: <module.js>; rel="modulepreload"

However /subdir/module.js preloaded doesn't exist. The intent is to preload /module.js due to the base URL in the document.

Expected behavior

The response should contain the following Link response header:

Link: </module.js>; rel="modulepreload"

Notice the slash / at the beginning

Seems the base URL of the document isn't taken into account to generate the automatic Link response header.

Steps to reproduce

Checkout a live site reproducing this:
https://cf-pages-hints-base.pages.dev/subdir/

You may inspect the source code and network requests to check out the generated Link header in the response is not the expected one.

The source code & how to reproduce the site is in this repository:
https://github.com/davidlj95/cf-pages-hints-href

It's deployed using the main command to do so using wrangler

Found this issue after some error logs started appearing in my personal website. You have to reload the page twice or so to trigger them. Angular generates some <link rel="modulepreload"> at the bottom of the <body> element. That due to this issue, leads to preloading inexistent files because of the incorrectly generated Link response in the header.

Please provide a link to a minimal reproduction

https://cf-pages-hints-base.pages.dev/subdir/

Please provide any relevant error logs

N/A

@davidlj95 davidlj95 added the bug Something that isn't working label Nov 6, 2024
@github-project-automation github-project-automation bot moved this to Untriaged in workers-sdk Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that isn't working
Projects
Status: Untriaged
Development

No branches or pull requests

1 participant