Skip to content

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

@deining

Description

@deining

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions