algolia / algolia/docsearch

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

Open
#2,502 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
4.4k
Forks
439
Avg merge
14h 32m
Merged PRs (30d)
19

Description

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](https://gohugo.io/functions/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 :
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](https://www.iana.org/assignments/media-types/application/javascript), 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.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the Hugo resources.GetRemote call for https://cdn.jsdelivr.net/npm/@docsearch/js@3 and compare it with the curl Content-Type response shown in the issue. Check whether the URL, filename extension, or delivered media type causes the failure; done means documenting a supported URL or a confirmed workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
hugo, javascript
Domain
web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.