Skip to content

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

@davidlj95

Description

@davidlj95

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

Metadata

Metadata

Labels

pagesRelating to Pages

Type

No fields configured for Bug.

Projects

Status

Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions