包括来自 raw.github.com 的 js [英] Including js from raw.github.com

查看:31
本文介绍了包括来自 raw.github.com 的 js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个链接到 https://raw.github.com/.../master/.../file.js 的 github.com 演示页面,所以我没有每次更改 .js 文件时,都需要将其复制到 gh-pages 分支.这适用于所有浏览器,除了 IE 抱怨:

I have a github.com demo page that is linking to https://raw.github.com/.../master/.../file.js so that I don't need to always copy the .js file over to the gh-pages branch every time it's changed. This works in every browser except IE which complains:

SEC7112:脚本来自 https://raw.github.com/cwolves/jQuery-iMask/master/dist/jquery-imask-min.js 因 mime 类型不匹配而被屏蔽

SEC7112: Script from https://raw.github.com/cwolves/jQuery-iMask/master/dist/jquery-imask-min.js was blocked due to mime type mismatch

此投诉来自文件传输的事实:

This complaint is coming from the fact that the file is transferred with:

X-Content-Type-Options: nosniff
Content-Type: text/plain

我无法改变.

有人对如何完成同样的事情有任何想法吗?以某种方式允许我链接到 master 分支中的文件,而不必总是将其推送到 gh-pages 分支?

Anyone have any ideas how to accomplish this same thing? Somehow allowing me to link to the file in the master branch without having to always push it to the gh-pages branch?

实际页面:http://cwolves.github.com/jQuery-iMask/

(小更新——我在这个确切的实例中更改了 gh-pages 以包含 .js 文件,因此 IE 不再损坏,但仍然需要任何反馈:))

(Minor update -- I changed the gh-pages in this exact instance to include the .js file, so IE is no longer broken, but would still like any feedback :))

推荐答案

我无法帮助你欺骗 IE,从这个角度我认为你正在寻找的东西是不可能的(并且气馁,因为这不是目的Github 的原始 URL).

I can't help you with tricking IE, and I think from that angle what you are looking for is impossible (and discouraged, since that is not the purpose of Github's raw URLs).

但是,您可以自动将更改提交到 gh-pages 并推动让您的生活更轻松.您可以使用 post-commit hook 来自动更新 gh-pages 分支中的相关文件.我编写了这样一个 post-commit 脚本,用于监视对某些文件的更改并将它们提交到另一个分支:

However, you can automate committing the changes to gh-pages and pushing to make your life easier. You can do it with a post-commit hook to update the relevant files in the gh-pages branch automatically. I've cooked up such a post-commit script that watches for changes to certain files and commits them to another branch:

#!/bin/sh

WATCH_BRANCH="master"
WATCH_FILES="jquery-imask-min.js"
DEST_BRANCH="gh-pages"

# bail out if this commit wasn't made in the watched branch
THIS_BRANCH=$(git branch --no-color | sed -e '/^[^*]/d' -e 's/* (.*)/1/');
if [ "$THIS_BRANCH" != "$WATCH_BRANCH" ]; then
  exit 0
fi

# only update if watched files have changed in the latest commit
CHANGED_FILES=$(git show --pretty="format:" --name-only $WATCH_BRANCH)
if $(echo "$CHANGED_FILES" | grep "^$WATCH_FILES$" -q); then
  # checkout destination branch, then
  # checkout latest version of each watched file and add to index
  git checkout -q $DEST_BRANCH
  git pull -q
  SAVEIFS=$IFS
  IFS=$(echo -n "|")
  for file in $WATCH_FILES; do
    git checkout $WATCH_BRANCH -- $file
    git add $file > /dev/null
  done
  IFS=$SAVEIFS
  # commit with a chance to edit the message, then go back to watched branch
  LATEST_COMMIT=$(git rev-parse $WATCH_BRANCH)
  git commit -m "Also including changes from $WATCH_BRANCH's $LATEST_COMMIT"
  git push origin $DEST_BRANCH
  git checkout -q $WATCH_BRANCH
fi

请注意,这是一个通用脚本,但我已在顶部指定了配置变量以供您使用.$WATCH_FILES 可以设置为以大括号| 分隔的文件列表,例如index.html|js/jquery.js.必须相对于存储库的根指定路径.

Note that this is a general script, though I have specified the config vars at the top for your purposes. $WATCH_FILES can be set to a list of files delimited by braces | such as index.html|js/jquery.js. Paths must be specified relative to the root of the repo.

如果您有任何问题,以及脚本是否对您有帮助,请告诉我!

Let me know if you have any questions, and if the script helps you!

这篇关于包括来自 raw.github.com 的 js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆