如何用github 的gh-pages 来host 自己的static网站

in #cn7 years ago (edited)

github_256.png


github 除了可以用来 host 你的代码的Repository , 也可以用来host 一个static 网站。

假设你的网站完全没有用到后端的processing , 只有前端例如 HTML, Javascript 和 CSS 的话, 基本上可以用 github 的 gh-pages 来host

例如我之前做的 狗狗冒险记 的小游戏

http://tensaix2j.github.io/dogewarrior/

好处是自己不用买vps, 而且github 的uptime 相对可靠, 不用maintenance


那要如何做呢?

非常简单, 假设你的代码repository 的 url 是

https://github.com/tensaix2j/dogewarrior

那么, 你首先需要开一个新branch 叫做 gh-pages ,
一旦有了 gh-pages 这个 branch, 你就可以用这个url 去access 项目以下的 static resources 了

https://用户名.github.io/项目名/任何static resources 例如 png,html,css,js, etc...


Example:

https://tensaix2j.github.io/dogewarrior/
    

就会直接用 gh-pages branch 里的 https://github.com/tensaix2j/dogewarrior/tree/gh-pages 的 index.html


那如果你想用ajax 做 http 到别人的网站拿资料,但别人不开Access-Control-Allow-Origin 给你呢?

可以参考上回写的这篇

https://steemit.com/cn/@tensaix2j/bypass-cors-same-origin-security-policy


谢谢阅读。

Sort:  

You got a 0.70% upvote from @postpromoter courtesy of @tensaix2j!

Want to promote your posts too? Check out the Steem Bot Tracker website for more info. If you would like to support the development of @postpromoter and the bot tracker please vote for @yabapmatt for witness!

Coin Marketplace

STEEM 0.17
TRX 0.15
JST 0.028
BTC 62007.73
ETH 2389.39
USDT 1.00
SBD 2.49