Link and execute external JavaScript file hosted on GitHub

前端 未结 15 1101
感动是毒
感动是毒 2020-11-22 04:08

When I try to change the linked reference of a local JavaScript file to a GitHub raw version my test file stops working. The error is:

Refused to exe

15条回答
  •  爱一瞬间的悲伤
    2020-11-22 04:15

    raw.github.com is not truely raw access to file asset, but a view rendered by Rails. So accessing raw.github.com is much heavier than needed. I don't know why raw.github.com is implemented as a Rails view. Instead of fix this route issue, GitHub added a X-Content-Type-Options: nosniff header.

    Workaround:

    • Put the script to user.github.io/repo
    • Use a third party CDN like rawgit.com.

提交回复
热议问题