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

Problems when retrieving JS script file from cdn.jsdelivr.net #2502

Open
deining opened this issue Feb 20, 2025 · 0 comments
Open

Problems when retrieving JS script file from cdn.jsdelivr.net #2502

deining opened this issue Feb 20, 2025 · 0 comments

Comments

@deining
Copy link

deining commented Feb 20, 2025

I'm successfull using docsearch on a hugo powered site.

Recently I ran into an issue: I'm retrieving algolia's script file via hugo's resources.GetRemote function.

{{ $url := "https://cdn.jsdelivr.net/npm/@docsearch/js@3" }}
{{ with try (resources.GetRemote $url) }}
  {{ with .Err }}
    {{ errorf "%s" . }}
  {{ end }}
{{ end }}

While this function call works fine with most other javascript files from other projets, it fails with algolia's one:

ERROR template: shortcodes/test.html:4:22: executing "shortcodes/test.html" at <resources.GetRemote>:
error calling GetRemote: failed to resolve media type for remote resource "https://cdn.jsdelivr.net/npm/@docsearch/js@3"

There are two reasons for this failure:

  • Unlike the filenames of many other libraries (e.g. katex.min.js) the algolia script file js has no extension.
  • The content type of the script file is application/javascript. According to IANA registry, this type is obsoleted in favor of text/javascript.
curl -s -I https://cdn.jsdelivr.net/npm/@docsearch/js@3 | grep content-type:
content-type: application/javascript; charset=utf-8

Questions

I was able to work around the issue described above, but questions remain:

  • Is there any way to get the algolia script file via an URL where the filename has extension .js?
  • Do have any influence on the content type delivered from cdn.jsdelivr.net? I would like to see content type text/javascript used here.

Thanks for your attention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant