热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

包括js从raw.github.com-Includingjsfromraw.github.com

Ihaveagithub.comdemopagethatislinkingtohttps:raw.github.commasterfile.jssoth

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:

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

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

SEC7112:来自https://raw.github.com/cwolves/jQuery-iMask/master/dist/jquery-imask-min.js的脚本由于mime类型不匹配而被阻塞

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

这项投诉是由于该文件是用下列方式传送的:

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

which I can't change.

我不能改变。

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?

有人知道怎么做同样的事情吗?不知怎么的,让我可以链接到主分支的文件,而不必总是把它推到ghpage分支上?

Actual page: http://cwolves.github.com/jQuery-iMask/

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

(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 :))

(小更新——我在这个实例中更改了ghl页面,以包含.js文件,所以IE不再被破坏,但仍然会像任何反馈一样:)

5 个解决方案

#1


14  

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).

我无法帮助您欺骗IE,我认为从这个角度来看,您所寻找的是不可能的(而且是不允许的,因为Github的原始url的目的并不是这样的)。

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:

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

#!/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

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.

注意,这是一个通用脚本,不过我已经为您的目的指定了顶部的配置vars。$WATCH_FILES可以设置为由大括号|分隔的文件列表,如index.html|js/jquery.js。路径必须相对于repo的根指定。

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

如果您有任何问题,请告诉我,如果脚本帮助您!

#2


61  

You can try using https://rawgithub.com/ service. Just replace raw.github.com with rawgithub.com.

您可以尝试使用https://rawgithub.com/服务。用rawgithub.com取代raw.github.com。

UPDATE

更新

Rawgithub is now Rawgit : https://rawgit.com/ and has added a production cdn as well.

现在,Rawgithub已经加入了一个生产cdn。

#3


6  

Take a look at raw.githack.com. The idea of this service is inspired from rawgit.com. I just realized that using a whole framework (node.js + express.js) for such simple thing as requests proxying is overkilling, and made same stuff using nginx only.

看看raw.githack.com。这项服务的灵感来自于rawgit.com。我刚刚意识到使用整个框架(node)。对于像请求代理这样简单的事情来说,使用nginx来做同样的事情是多余的。

Replace "githubusercontent" domain name chunk in your github/gist URL with "githack" and you're done!

用“githack”替换github/gist URL中的“githuerbusercontent”域名块,就完成了!

Furthermore, it supports bitbucket.com - simply replace whole bitbucket domain with bb.githack.com.

此外,它还支持bitbucket.com——只需用bb.githack.com替换整个bitbucket域。

#4


5  

Github's raw URLs aren't designed to be a generic web host. Push that stuff off to proper host, like say pages.github.com.

Github的原始url并不是设计成一般的web主机。把这些东西推到合适的主机上,比如pages.github.com。

#5


0  

I am also trying to achieve this. However, I cannot seem to get the solution from @shelhamer to work in my codebase. Below is the updated post-commit hook script that I used to get it working:

我也在努力做到这一点。然而,我似乎无法从@shelhamer那里得到解决方案,在我的代码库中工作。下面是我用来让它工作的更新后提交钩子脚本:

#!/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

I had to update the use of grep to make the regex successfully match (-P was not an option on the grep implementation included in Git Bash shell for Windows), add a git pull and a git push origin $DEST_BRANCH. Oh, and I had to add an empty shell of the directories and files in advance (perhaps just the directories would have sufficed?).

我必须更新grep的使用,以使regex成功匹配(-P不是grep实现的一个选项,它包含在Windows的Git Bash shell中),添加一个Git pull和一个Git push origin $DEST_BRANCH。哦,我还必须预先添加目录和文件的空shell(也许仅仅是目录就足够了?)

Since this is actually doing a push, I think it may be better to switch this script to being a post-receive script instead of post-commit. Otherwise, you could be pushing code to gh-pages that never made it into master [if you choose not to push it].

由于这实际上是在推动,所以我认为最好将该脚本转换为后接收脚本,而不是后提交脚本。否则,您可能会将代码推到从未进入master的gh-pages(如果您选择不推的话)。


推荐阅读
author-avatar
jytujtuyt
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有