development

raw.github.com의 js 포함

big-blog 2021. 1. 7. 20:36
반응형

raw.github.com의 js 포함


https://raw.github.com/.../master/.../file.js에 연결되는 github.com 데모 페이지가 있으므로 .js파일 을 항상 복사 할 필요가 없습니다 . gh-pages변경 될 때마다 분기합니다. 이것은 불평하는 IE를 제외한 모든 브라우저에서 작동합니다.

SEC7112 : https://raw.github.com/cwolves/jQuery-iMask/master/dist/jquery-imask-min.js의 스크립트 가 MIME 유형 불일치로 인해 차단되었습니다.

이 불만은 파일이 다음과 함께 전송된다는 사실에서 비롯됩니다.

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

변경할 수 없습니다.

누구든지이 같은 일을 수행하는 방법에 대한 아이디어가 있습니까? 어떻게 든 master항상 gh-pages브랜치로 푸시하지 않고도 브랜치 의 파일에 링크 할 수 있습니까?

실제 페이지 : http://cwolves.github.com/jQuery-iMask/

(사소한 업데이트-.js 파일을 포함하도록이 정확한 인스턴스에서 gh-pages를 변경 했으므로 IE는 더 이상 손상되지 않지만 피드백을 원합니다. :))


나는 IE를 속이는 데 도움을 줄 수 없으며, 그 각도에서 찾고있는 것이 불가능하다고 생각합니다 (Github의 원시 URL의 목적이 아니기 때문에 권장하지 않습니다).

그러나 변경 사항 커밋 gh-pages및 푸시를 자동화 하여 삶을 더 쉽게 만들 수 있습니다. a post-commit hook를 사용하여 gh-pages분기 의 관련 파일을 자동으로 업데이트 할 수 있습니다 . post-commit특정 파일의 변경 사항을 감시하고 다른 분기에 커밋 하는 스크립트를 작성했습니다.

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

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


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

UPDATE

The Rawgit service (former Rawgithub) has been shutdown.

RawGit has reached the end of its useful life October 8, 2018

GitHub repositories that served content through RawGit within the last month will continue to be served until at least October of 2019. URLs for other repositories are no longer being served.

If you're currently using RawGit, please stop using it as soon as you can.


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.

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

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


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.


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:

#!/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?).

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

ReferenceURL : https://stackoverflow.com/questions/7180099/including-js-from-raw-github-com

반응형