Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何直接从Github链接文件(raw.Github.com)_Github_Github Pages_Cdn - Fatal编程技术网

如何直接从Github链接文件(raw.Github.com)

如何直接从Github链接文件(raw.Github.com),github,github-pages,cdn,Github,Github Pages,Cdn,我们可以直接从Github链接文件吗 我知道这是谷歌代码允许的。这样我就不必担心更新本地文件。您可以直接链接到原始文件,但最好不要这样做,因为原始文件总是以纯文本头发送,并可能导致加载问题。您可以直接链接到原始文件,但最好不要这样做,因为原始文件总是以纯文本标题发送,可能会导致加载问题。使用名称“gh pages”在项目中添加一个分支,然后(分支后不久)就可以使用直接URL,例如(使用URL,并假设“style.css”是“master”中的文件)“项目”存储库根目录中的文件夹…并且您的Gi

我们可以直接从Github链接文件吗



我知道这是谷歌代码允许的。这样我就不必担心更新本地文件。

您可以直接链接到原始文件,但最好不要这样做,因为原始文件总是以纯文本头发送,并可能导致加载问题。

您可以直接链接到原始文件,但最好不要这样做,因为原始文件总是以纯文本标题发送,可能会导致加载问题。

使用名称“gh pages”在项目中添加一个分支,然后(分支后不久)就可以使用直接URL,例如(使用URL,并假设“style.css”是“master”中的文件)“项目”存储库根目录中的文件夹…并且您的Github帐户是“用户名”)。

使用名称“gh pages”为项目添加一个分支,然后(分支后不久)您将能够使用直接URL,例如(使用您的URL,并假设“style.css”是“项目”根目录中“master”文件夹中的文件)存储库…并且您的Github帐户是“用户名”)。

您可以使用外部服务器
rawgithub.com
。只需删除单词“raw”和“github”之间的一个点即可……=>并使用它


但是,根据rawgithub网站,它将于2019年10月底关闭。

您可以使用外部服务器
rawgithub.com
。只需删除单词“raw”和“github”之间的一个点即可……=>并使用它


但是,根据rawgithub网站,它将于2019年10月底关闭。

您需要执行以下步骤

  • 从github获取文件的原始url。这有点像

  • 访问。将上面的git url粘贴到输入框中。它将生成两个url,一个用于开发,另一个用于生产

  • 复制其中任何一个,你就完成了


  • 该文件将充当CDN。您还可以使用gist URL。

    您需要执行以下步骤

  • 从github获取文件的原始url。这有点像

  • 访问。将上面的git url粘贴到输入框中。它将生成两个url,一个用于开发,另一个用于生产

  • 复制其中任何一个,你就完成了


  • 该文件将充当CDN。您也可以使用gist URL。

    在搜索相同的功能后,我最终编写了自己的
    PHP
    脚本作为代理。我一直遇到的问题是,即使当您从
    Github
    获取原始版本/链接并在自己的页面中链接到它时,发送过来的标题是“text/plain”,并且
    Chrome
    没有执行
    Github
    中的
    JavaScript
    文件。我也不喜欢其他使用第三方服务的链接,因为可能存在明显的安全/篡改问题

    因此,使用这个脚本,我可以从
    Github
    传递原始链接,让脚本设置正确的头,然后输出文件,就像它来自我自己的服务器一样。此脚本还可以与安全应用程序一起使用,以拉入非安全脚本,而不会抛出“使用了非安全链接”的
    SSL
    错误警告

    链接:

    proxy.php

    <?php
    ###################################################################################################################
    # 
    # This script can take two URL variables
    # 
    # "type"
    #   OPTIONAL
    #   STRING
    #   Sets the type of file that is output
    # 
    # "link"
    #   REQUIRED
    #   STRING
    #   The link to grab and output through this proxy script
    # 
    ###################################################################################################################
    
    
    
    # First we need to set the headers for the output file
    # So check to see if the type is specified first and if so, then set according to what is being requested
    if(isset($_GET['type']) && $_GET['type'] != ''){
        switch($_GET['type']){
            case 'css':
                header('Content-Type: text/css');
                break;
    
            case 'js':
                header('Content-Type: text/javascript');
                break;
    
            case 'json':
                header('Content-Type: application/json');
                break;
    
            case 'rss':
                header('Content-Type: application/rss+xml; charset=ISO-8859-1');
                break;
    
            case 'xml':
                header('Content-Type: text/xml');
                break;
    
            default:
                header('Content-Type: text/plain');
                break;
        }
    
    # Otherwise, try and determine what file type should be output by the file extension from the link
    }else{
        # See if we can find a file type in the link specified and set the headers accordingly
    
        # If css file extension is found, then set the headers to css format
        if(strstr($_GET['link'], '.css') != FALSE){
            header('Content-Type: text/css');
    
        # If javascript file extension is found, then set the headers to javascript format
        }elseif(strstr($_GET['link'], '.js') != FALSE){
            header('Content-Type: text/javascript');
    
        # If json file extension is found, then set the headers to json format
        }elseif(strstr($_GET['link'], '.json') != FALSE){
            header('Content-Type: application/json');
    
        # If rss file extension is found, then set the headers to rss format
        }elseif(strstr($_GET['link'], '.rss') != FALSE){
            header('Content-Type: application/rss+xml; charset=ISO-8859-1');
    
        # If css xml extension is found, then set the headers to xml format
        }elseif(strstr($_GET['link'], '.xml') != FALSE){
            header('Content-Type: text/xml');
    
        # If we still haven't found a suitable file extension, then just set the headers to plain text format
        }else{
            header('Content-Type: text/plain');
        }
    }
    
    # Now get the contents of our page we're wanting
    $contents = file_get_contents($_GET['link']);
    
    # And finally, spit everything out
    echo $contents;
    ?>
    

    在搜索相同的功能后,我最终编写了自己的
    PHP
    脚本作为代理。我一直遇到的问题是,即使当您从
    Github
    获取原始版本/链接并在自己的页面中链接到它时,发送过来的标题是“text/plain”,并且
    Chrome
    没有执行
    Github
    中的
    JavaScript
    文件。我也不喜欢其他使用第三方服务的链接,因为可能存在明显的安全/篡改问题

    因此,使用这个脚本,我可以从
    Github
    传递原始链接,让脚本设置正确的头,然后输出文件,就像它来自我自己的服务器一样。此脚本还可以与安全应用程序一起使用,以拉入非安全脚本,而不会抛出“使用了非安全链接”的
    SSL
    错误警告

    链接:

    proxy.php

    <?php
    ###################################################################################################################
    # 
    # This script can take two URL variables
    # 
    # "type"
    #   OPTIONAL
    #   STRING
    #   Sets the type of file that is output
    # 
    # "link"
    #   REQUIRED
    #   STRING
    #   The link to grab and output through this proxy script
    # 
    ###################################################################################################################
    
    
    
    # First we need to set the headers for the output file
    # So check to see if the type is specified first and if so, then set according to what is being requested
    if(isset($_GET['type']) && $_GET['type'] != ''){
        switch($_GET['type']){
            case 'css':
                header('Content-Type: text/css');
                break;
    
            case 'js':
                header('Content-Type: text/javascript');
                break;
    
            case 'json':
                header('Content-Type: application/json');
                break;
    
            case 'rss':
                header('Content-Type: application/rss+xml; charset=ISO-8859-1');
                break;
    
            case 'xml':
                header('Content-Type: text/xml');
                break;
    
            default:
                header('Content-Type: text/plain');
                break;
        }
    
    # Otherwise, try and determine what file type should be output by the file extension from the link
    }else{
        # See if we can find a file type in the link specified and set the headers accordingly
    
        # If css file extension is found, then set the headers to css format
        if(strstr($_GET['link'], '.css') != FALSE){
            header('Content-Type: text/css');
    
        # If javascript file extension is found, then set the headers to javascript format
        }elseif(strstr($_GET['link'], '.js') != FALSE){
            header('Content-Type: text/javascript');
    
        # If json file extension is found, then set the headers to json format
        }elseif(strstr($_GET['link'], '.json') != FALSE){
            header('Content-Type: application/json');
    
        # If rss file extension is found, then set the headers to rss format
        }elseif(strstr($_GET['link'], '.rss') != FALSE){
            header('Content-Type: application/rss+xml; charset=ISO-8859-1');
    
        # If css xml extension is found, then set the headers to xml format
        }elseif(strstr($_GET['link'], '.xml') != FALSE){
            header('Content-Type: text/xml');
    
        # If we still haven't found a suitable file extension, then just set the headers to plain text format
        }else{
            header('Content-Type: text/plain');
        }
    }
    
    # Now get the contents of our page we're wanting
    $contents = file_get_contents($_GET['link']);
    
    # And finally, spit everything out
    echo $contents;
    ?>
    

    RawGit的出色服务已经被提及,但我将在拳击场上再介绍一个:

    好处:

    • 允许您链接到特定的提交,以及自动获取最新的(又名master)
    • 不会因高交通量而造成损坏;RawGit要求它的dev.RawGit.com链接只能在开发期间使用,因为GitCDN允许您访问最新版本,而不会有服务器爆炸的危险
    • 为您提供自动缩小HTML、CSS和JavaScript的选项,或将其作为书面形式提供()
    • 添加压缩(GZip)
    • 添加所有正确的标题(内容类型、缓存控制、电子标签等)

    完全公开,我是

    的项目维护者,RawGit的伟大服务已经被提及,但我将在拳击场上抛出另一个:

    好处:

    • 允许您链接到特定的提交,以及自动获取最新的(又名master)
    • 不会因高交通量而造成损坏;RawGit要求它的dev.RawGit.com链接只能在开发期间使用,因为GitCDN允许您访问最新版本,而不会有服务器爆炸的危险
    • 为您提供自动缩小HTML、CSS和JavaScript的选项,或将其作为书面形式提供()
    • 添加压缩(GZip)
    • 添加所有正确的标题(内容类型、缓存控制、电子标签等)

    完全公开,我是GitHub页面的项目维护人员:
    https://yourusername.github.io/script.js

    GitHub repo原始文件:
    https://github.com/yourusername/yourusername.github.io/blob/master/script.js

    使用GitHub页面,不要