跳到正文
博客

Gist "Refused to execute script" MIME type text/plain

Gist raw URLs answer as text/plain, so browsers block them as scripts. Why it happens, what won't work, and how to serve the JS with the right content type.

The Liite team阅读约 7 分钟

Short answer

A raw Gist URL is served as text/plain, and browsers refuse to run a <script src> whose response isn't a JavaScript type when nosniff is set. Serve the same file from a host that sends a JavaScript content type: a normal repo behind a CDN, your own web server, or a static host such as a Liite uploaded site. Then check the Content-Type response header in the network tab.

You pointed a <script> tag at a Gist's raw URL, and the console shows this instead of your code running:

Refused to execute script from 'https://gist.githubusercontent.com/…' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled.

The code is fine. The problem is the header the raw URL sends back with it.

Why Gist raw URLs fail as scripts

Browsers check the Content-Type of a script response before running it. MDN's page on X-Content-Type-Options explains that with nosniff, the browser blocks a script or stylesheet response if the MIME type isn't an expected one, meaning a JavaScript type for scripts. The Fetch standard describes the same check: a script-like request is blocked when the MIME type isn't a JavaScript MIME type and nosniff is present.

Raw Gist URLs answer with text/plain. Renaming the file to .js inside the gist does not change that header, which is why the error survives every rename. We don't know GitHub's reasoning for serving raw files this way, so we won't guess.

The usual workaround is a proxy CDN that rewrites the content type. As of November 2026, an issue in the jsDelivr GitHub repository (issue 18276) says jsDelivr doesn't proxy gists, so the common cdn.jsdelivr.net/gh/... pattern doesn't apply to them. Check that issue for the current status, since it could change.

Userscripts hit a related wall. People on the r/userscripts forum have reported a script hosted on a gist that wouldn't auto-update in their userscript manager. The cause wasn't confirmed there, so check your manager's documentation for the update URL it expects.

CauseWhat you seeFix
Raw Gist URL as <script src>"Refused to execute script … text/plain"Host the file where .js gets a JavaScript type
.js renamed inside the gistSame errorRename doesn't change the header; move the file
CDN that doesn't proxy gists404 or an error from the CDNPut the file in a repo or other host
Cached old responseError persists after the moveHard-reload and check the new header

How to fix it

Most likely fix first. After each one, open the browser's developer tools, go to the Network tab, click the script request and read the Content-Type response header.

1. Move the file into a normal repository and use a repo-aware CDN

A repository is not a gist. If the file can live in a public repo, a CDN built for repos is the standard route. Check your CDN's documentation for the exact URL format and whether it pins versions.

2. Serve it from a web server you already have

Drop the file next to your pages. Most web servers map .js to a JavaScript type by default. MDN's Apache guide notes that servers should use text/javascript for JavaScript resources, so a server that sends anything else is misconfigured.

3. Upload it as a static site on Liite

  1. Put app.js in a folder, or in a .zip with a small index.html next to it.
  2. Sign in at liite.co and upload the folder or zip as a new uploaded site. Liite's allowed file types include js and mjs.
  3. Open the site's page in your dashboard and note its address, which has the form <slug>.liite.site.
  4. Point your script tag at the file's path on that address:
<script src="https://your-slug.liite.site/app.js"></script>
  1. Reload the page that uses it, then check the Content-Type header as described above.

Each uploaded site is its own origin, and user JavaScript is served only on liite.site, never on liite.co. To update the script, upload again. The address stays the same, and older versions are kept for rollback (3 on Free, 20 on Pro).

Free sites expire

A Free uploaded site needs a card on file and goes offline 7 days after the last publish. That suits a quick test, not a script other pages depend on. Paid sites don't expire.

4. Inline the script

If it is short and used on one page, paste it into a <script> block. There is no request, so there is no MIME check.

5. Userscripts

Name the file so it ends in .user.js, keep the URL stable and public, and use that URL as the install address. Managers generally compare the @version line to decide whether to update, so bump it each time you publish.

What won't help

  • Renaming the file to .js in the gist. The raw URL still answers text/plain.
  • Adding type="text/javascript" to the script tag. MDN notes that this is the default and not needed. It also doesn't override the response header.
  • Using the gist's embed snippet. It is built to display a gist on a page, not to load your code as a library.
  • Turning off MIME checking in your browser. It hides the error on your machine only. Your visitors still hit it.
  • Switching between gist.github.com and gist.githubusercontent.com. The raw URL is the one that returns plain text, and swapping hosts doesn't change that.

Cross-origin and module scripts

A classic <script src> can load from another origin without special headers. For type="module" scripts, the host must also allow cross-origin requests, which depends on its response headers. We haven't verified what headers Liite sends for that case, so test it before relying on it. If a module fails, the console usually names the missing CORS header.

Checklist before you try again

  • The script URL no longer contains gist.githubusercontent.com.
  • The Content-Type response header names a JavaScript type, such as text/javascript.
  • The URL opens in a browser tab without a login or redirect.
  • You hard-reloaded the page, so a cached response isn't masking the fix.
  • For modules, the host allows cross-origin requests.

If nothing works

Contact your host or CDN support. For GitHub-side questions, use GitHub Support. Include the exact console error, the script URL, the Content-Type header you see in the network tab, and what you already tried.

Subject: Script served with the wrong Content-Type

My page loads a script from <URL>. The browser console shows:
"Refused to execute script from '<URL>' because its MIME type
('text/plain') is not executable, and strict MIME type checking
is enabled."

The response header in the Network tab is: Content-Type: <value>.
I have tried: moving the file, hard-reloading, checking the
extension. Can you confirm which Content-Type this file should
be served with? Time of the failed request: <timestamp>.

Common questions

Can I make a Gist serve as JavaScript with a query string or file extension?

No. The raw URL's header stays text/plain whatever the file is called, so the fix has to be a different host.

Why does the same file work when I open it in a tab?

Opening a URL in a tab just displays text. The MIME check applies only when the browser loads the response as a script.

Is it safe to relax the check?

MDN's MIME type guide says the header exists so that browsers don't load scripts and stylesheets unless the server indicates the correct MIME type. The fix is to serve the right type, not to weaken the check.

If you'd rather not deal with this again

Liite's uploaded sites serve static files, including .js and .mjs, at <slug>.liite.site. Upload once, update by uploading again, and the address stays put. Paid sites never expire, with up to 25 MB per site on Pro. Liite can't run server-side code, so this only works for static files. See free HTML hosting or the uploaded sites docs.