简体   繁体   English

从不同的服务器/主机加载脚本,而不是我的

[英]Load script from different server/host , rather than my

I'm looking for the place where i can put my js script file.我正在寻找可以放置我的 js 脚本文件的地方。 I'm creating javascript code like an Google Analitics code, so it will load an .js file, but my server cannot handle so many requests.我正在创建类似于 Google Analitics 代码的 javascript 代码,因此它将加载一个 .js 文件,但我的服务器无法处理如此多的请求。 I'm thinking to upload my script to another server.我正在考虑将我的脚本上传到另一台服务器。 Maybe it is possible and legal?也许这是可能的和合法的? For example github?例如github? goolgle disk?谷歌磁盘? Thanks.谢谢。

Some tests loads .js from raw.github, you would call to it in the same way than local scripts: 一些测试从raw.github加载.js,您将以与本地脚本相同的方式调用它:

<!-- local -->
<script src="animation.js"></script>

<!-- remote -->
<script src="https://raw.githubusercontent.com/PRDeving/HTMLAnimation/master/animation.js"></script>

Unless you have acces to the host server and allows cross origin, you gonna have to ask for the remotes from a secure server (https) or it wont work. 除非您具有访问主机服务器的权限并允许跨源访问,否则您将不得不从安全服务器(https)请求远程服务器,否则它将无法正常工作。

It's legal and easy but, if it's a final app you should go for a statics server like amazon WS. 这是合法且容易的,但是,如果这是最终的应用程序,则应购买像Amazon WS这样的静态服务器。

I don't think that Google accepts scripts without STRONG backup info about and testing. 我认为Google接受的脚本如果没有有关测试的强大备份信息,就不会接受。 jQuery is hosted on MAX CDN, they offer a free trial, and in the future for more requests or number of files you have to pay. jQuery托管在MAX CDN上,它们提供免费试用,并且将来还会有更多请求或您需要支付的文件数量。 Here is the link 链接在这里

MAXCDN 最大CDN

You can chose to pay per bandwidth or a subscription by month, the lowest being: 您可以选择按带宽或按月付费,最低的是:

100GB bandwidth/month 100GB带宽/月

$9 per month 每月$ 9

8¢ per GB overage* 每超出1 GB,仅收取8¢*

2 websites (zones) 2个网站(区域)

Hope it helps. 希望能帮助到你。

(I know this is an old thread - but Google popped this up while I was searching for something tangentially related, so thought it could use some updates on more recent options) (我知道这是一个旧线程 - 但谷歌在我搜索相关的东西时弹出了这个,所以认为它可以使用更新选项的一些更新)

I'm thinking to upload my script to another server.我正在考虑将我的脚本上传到另一台服务器。 Maybe it is possible and legal?也许这是可能的和合法的? For example github?例如github? goolgle disk?谷歌磁盘? Thanks.谢谢。

  • Possible: yes - if permitted可能:是 - 如果允许
  • Legal: yes - if permitted ☺合法:是 - 如果允许 ☺

Web servers set couple of header fields called Cross-Origin-Resource-Sharing (Cors) (read more here: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin ) If the server has been configured to allow it's files to be pulled into other sites (ie, sets the Cors header to a permissive value), then it will work. Web 服务器设置了几个标题字段,称为 Cross-Origin-Resource-Sharing (Cors)(在此处阅读更多信息: https : //developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin )如果服务器已配置为允许将其文件拉入其他站点(即,将 Cors 标头设置为允许值),然后它将起作用。

Web sites also set a header field to prevent user injection from untrusted locations.网站还设置了一个标头字段以防止用户从不受信任的位置注入。 This is called Content-Security-Policy (CSP) - Facebook for example sets one that all images and scripts must come from Facebooks servers.这称为内容安全策略 (CSP) - 例如 Facebook 设置了一个所有图像和脚本必须来自 Facebook 的服务器。 (Read more on setting this header in a JavaScript app here: https://www.digitalocean.com/community/tutorials/how-to-secure-node-js-applications-with-a-content-security-policy ) (在此处阅读有关在 JavaScript 应用程序中设置此标头的更多信息: https : //www.digitalocean.com/community/tutorials/how-to-secure-node-js-applications-with-a-content-security-policy

Some web servers that I'm aware of that are permissive in this manner:我所知道的一些网络服务器以这种方式允许:

  • raw.githubusercontent.com (the raw pages on GitHub) raw.githubusercontent.com(GitHub 上的原始页面)
  • GitHub Pages (if you put your source in GitHub and turn on GitHub Pages, by default Cors is allowed - at least for now) GitHub Pages(如果您将源代码放在 GitHub 中并打开 GitHub Pages,则默认情况下允许使用 Cors - 至少目前如此)
  • Any CDN (Content-Delivery-Network) server: There are a bunch of these and they range in price vs guaranteed up time (google it if the following don't meet your needs)任何 CDN(内容交付网络)服务器:有很多这样的服务器,它们的价格与保证正常运行时间不同(如果以下内容不满足您的需求,请谷歌一下)
    • jsdelivr.com - a free CDN for anything in the npm repo, on GitHub, or WordPress plugins jsdelivr.com - 适用于 npm 存储库、GitHub 或 WordPress 插件中任何内容的免费 CDN
    • Cloudflare (free plan or paid) Cloudflare(免费计划或付费)
    • Stackpath.com (what JQuery uses at present - paid plans only it looks like) Stackpath.com(JQuery 目前使用的 - 付费计划只是看起来像)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM