{"id":1294,"date":"2023-07-09T00:13:28","date_gmt":"2023-07-08T17:13:28","guid":{"rendered":"https:\/\/dev.artru.eu.org\/?p=1294"},"modified":"2023-10-27T14:37:57","modified_gmt":"2023-10-27T07:37:57","slug":"su-dung-github-lam-cdn-cho-website","status":"publish","type":"post","link":"https:\/\/artru.net\/zh\/su-dung-github-lam-cdn-cho-website\/","title":{"rendered":"\u4f7f\u7528 GitHub \u4f5c\u4e3a\u60a8\u7f51\u7ad9\u7684 CDN"},"content":{"rendered":"<h2 class=\"wp-block-heading\">\u4ec0\u4e48\u662fCDN\uff1f<\/h2>\n\n\n\n<p>CDN\uff08\u5185\u5bb9\u4ea4\u4ed8\u7f51\u7edc\uff09\u662f\u4e00\u79cd\u5185\u5bb9\u4ea4\u4ed8\u7f51\u7edc\uff0c\u901a\u8fc7\u5728\u7528\u6237\u4f4d\u7f6e\u9644\u8fd1\u7684\u670d\u52a1\u5668\u4e0a\u5b58\u50a8\u9759\u6001\u6587\u4ef6\uff08\u4f8b\u5982\u56fe\u50cf\u3001CSS\u3001JavaScript\u3001\u5b57\u4f53\u3001\u89c6\u9891...\uff09\u6765\u5e2e\u52a9\u52a0\u5feb\u7f51\u7ad9\u52a0\u8f7d\u901f\u5ea6\u3002<\/p>\n\n\n\n<p>\u901a\u8fc7\u4f7f\u7528CDN\uff0c\u60a8\u53ef\u4ee5\u6700\u5927\u9650\u5ea6\u5730\u51cf\u5c11\u7528\u6237\u7b49\u5f85\u65f6\u95f4\uff0c\u51cf\u8f7b\u6e90\u7ad9\u8d1f\u8f7d\uff0c\u8282\u7701\u5e26\u5bbd\uff0c\u63d0\u5347\u7528\u6237\u4f53\u9a8c\u3002<\/p>\n\n\n\n<p>\u7136\u800c\uff0c\u5e76\u4e0d\u662f\u6bcf\u4e2a\u4eba\u90fd\u6709\u80fd\u529b\u4f7f\u7528\u4e13\u4e1a\u7684 CDN \u670d\u52a1\uff0c\u5c24\u5176\u662f\u90a3\u4e9b\u521a\u521a\u8d77\u6b65\u6216\u9884\u7b97\u7d27\u5f20\u7684\u4eba\u3002<\/p>\n\n\n\n<p>\u90a3\u4e48\u6709\u6ca1\u6709\u529e\u6cd5\u4e3a\u60a8\u7684\u7f51\u7ad9\u4f7f\u7528\u514d\u8d39\u4e14\u7b80\u5355\u7684 CDN \u5462\uff1f\u7b54\u6848\u662f\u201c\u662f\u201d\uff0c\u90a3\u5c31\u662f\u4f7f\u7528GitHub\u4f5c\u4e3a\u7f51\u7ad9\u7684CDN\u3002<\/p>\n\n\n\n<p>GitHub \u662f\u4e00\u79cd\u6d41\u884c\u7684 Git \u6e90\u4ee3\u7801\u6258\u7ba1\u670d\u52a1\uff0c\u5141\u8bb8\u60a8\u521b\u5efa\u548c\u7ba1\u7406\u8f6f\u4ef6\u9879\u76ee\u7684\u516c\u5171\u6216\u79c1\u6709\u5b58\u50a8\u5e93\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528 GitHub \u6258\u7ba1\u7f51\u7ad9\u7684\u9759\u6001\u6587\u4ef6\uff0c\u5e76\u4f7f\u7528\u5176\u4ed6\u514d\u8d39 CDN \u670d\u52a1\u5c06\u5185\u5bb9\u4ece GitHub \u4f20\u9001\u5230\u60a8\u7684\u7f51\u7ad9\u3002<\/p>\n\n\n\n<p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5c06\u5411\u60a8\u4ecb\u7ecd GitHub \u4e0a\u53ef\u7528\u4e8e\u60a8\u7684\u7f51\u7ad9\u7684 2 \u4e2a\u514d\u8d39 CDN \u670d\u52a1\uff0c\u5373 jsDelivr \u548c raw.githack\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">jsDelivr<\/h2>\n\n\n\n<p>jsDelivr \u662f\u4e00\u4e2a\u514d\u8d39\u3001\u5feb\u901f\u3001\u7a33\u5b9a\u7684\u5f00\u6e90 CDN \u670d\u52a1\uff0c\u652f\u6301 npm \u548c GitHub \u4e0a\u5f00\u6e90\u8f6f\u4ef6\u7684 CDN\u3002<\/p>\n\n\n\n<p>jsDelivr \u7531\u56db\u5927 CDN \u652f\u6301\uff1aCloudflare\u3001Fastly\u3001Bunny \u548c Quantil\uff0c\u62e5\u6709\u8d85\u8fc7 750 \u4e2a\u5168\u7403\u63a5\u5165\u70b9\uff0c\u652f\u6301\u81ea\u52a8\u8d1f\u8f7d\u5e73\u8861\uff0c\u6bd4\u5927\u591a\u6570\u5176\u4ed6 CDN \u66f4\u5feb\u5e76\u4e14\u8fd0\u884c\u5b8c\u7f8e\uff0c\u5373\u4f7f\u5728\u4e2d\u56fd\u4e5f\u662f\u5982\u6b64\u3002<\/p>\n\n\n\n<p>\u8981\u4f7f\u7528 jsDelivr\uff0c\u60a8\u9700\u8981\u590d\u5236 GitHub \u4e0a\u6587\u4ef6\u7684\u94fe\u63a5\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\" data-no-translation=\"\" data-no-auto-translation=\"\"><code data-no-translation=\"\" data-no-auto-translation=\"\">https:&#47;&#47;github.com\/twbs\/bootstrap\/blob\/v4-dev\/dist\/css\/bootstrap.min.css<\/code><\/pre>\n\n\n\n<p>\u7136\u540e\u60a8\u8fdb\u5165 jsDelivr \u4e3b\u9875 \u2192 \u6807\u9898\u4e0a\u65b9\u7684\u201c\u5de5\u5177\u201d\u5de5\u5177 \u2192 \u9009\u62e9\u4ece\u201cGitHub\u201d\u6216\u60a8\u62e5\u6709\u7684\u4efb\u4f55\u6765\u6e90\u8fdb\u884c\u8f6c\u6362\u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1054\" height=\"658\" src=\"https:\/\/cdn.artru.eu.org\/wp-content\/uploads\/2023\/07\/Migrating-from-GitHub-to-jsDelivr.png\" alt=\"\u4ece GitHub \u8fc1\u79fb\u5230 jsDelivr\" class=\"wp-image-1339\"\/><figcaption class=\"wp-element-caption\">\u4ece GitHub \u8fc1\u79fb\u5230 jsDelivr<\/figcaption><\/figure>\n<\/div>\n\n\n<p>\u5c06\u4e0a\u9762\u4ece GitHub \u83b7\u53d6\u7684\u6587\u4ef6 url \u7c98\u8d34\u5230\u8f93\u5165\u6846\u4e2d\uff0c\u5b83\u5c06\u8f6c\u6362\u4e3a jsDelivr url\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\" data-no-translation=\"\" data-no-auto-translation=\"\"><code data-no-translation=\"\" data-no-auto-translation=\"\">https:&#47;&#47;cdn.jsdelivr.net\/gh\/twbs\/bootstrap@v4-dev\/dist\/css\/bootstrap.min.css<\/code><\/pre>\n\n\n\n<p>\u60a8\u53ef\u4ee5\u5728\u6807\u7b7e\u4e2d\u4f7f\u7528\u6b64 CDN \u94fe\u63a5 <code data-no-translation=\"\" data-no-auto-translation=\"\">&lt;link&gt;<\/code> \u6216\u8005 <code data-no-translation=\"\" data-no-auto-translation=\"\">&lt;script&gt;<\/code> \u5728\u7f51\u7ad9\u4e0a\u4ece jsDelivr \u52a0\u8f7d\u5185\u5bb9\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528 jsDelivr \u7684\u5176\u4ed6\u529f\u80fd\uff0c\u5982\u7f29\u5c0f\u3001\u4e32\u8054\u3001\u7248\u672c\u522b\u540d\u3001SRI \u54c8\u5e0c...\u6765\u4f18\u5316\u5185\u5bb9\u3002<\/p>\n\n\n\n<p>\u5728\u8fd9\u91cc\u67e5\u770b jsDelivr \u7684\u66f4\u591a\u6587\u6863\uff1a <a href=\"https:\/\/www.jsdelivr.com\/features\" target=\"_blank\" data-schema-attribute=\"about\" rel=\"noreferrer noopener\">jsdelivr-\u529f\u80fd<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u539f\u59cb.githack<\/h2>\n\n\n\n<p>raw.githack \u4e5f\u662f\u4e00\u4e2a\u514d\u8d39\u7684 CDN \u670d\u52a1\uff0c\u5141\u8bb8\u60a8\u76f4\u63a5\u4ece GitHub \u548c GitLab \u4e0a\u7684\u516c\u5171\u5b58\u50a8\u5e93\u5206\u53d1\u6587\u4ef6\u3002 raw.githack \u4f7f\u7528 Cloudflare \u7f51\u7edc\u6765\u786e\u4fdd\u5185\u5bb9\u7684\u9ad8\u6027\u80fd\u548c\u53ef\u9760\u6027\u3002<\/p>\n\n\n\n<p>\u8981\u4f7f\u7528 raw.githack\uff0c\u60a8\u9700\u8981 GitHub \u6587\u4ef6\u7684\u94fe\u63a5\uff0c\u4f8b\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\" data-no-translation=\"\" data-no-auto-translation=\"\"><code data-no-translation=\"\" data-no-auto-translation=\"\">https:&#47;&#47;github.com\/jquery\/jquery\/blob\/main\/src\/core.js<\/code><\/pre>\n\n\n\n<p>\u60a8\u53ea\u9700\u8981\u8bbf\u95ee\u4ee5\u4e0b\u7f51\u7ad9 <a href=\"https:\/\/raw.githack.com\/\" target=\"_blank\" data-schema-attribute=\"about\" rel=\"noreferrer noopener\">\u539f\u59cb.githack<\/a> \u5c06GitHub\u94fe\u63a5\u7c98\u8d34\u5230\u8f93\u5165\u6846\u4e2d\uff0c\u5373\u53ef\u83b7\u53d6raw.githack\u7684CDN\u94fe\u63a5\u3002<\/p>\n\n\n\n<p>\u6211\u4eec\u5c06\u5f97\u5230 2 \u4e2a\u7ed3\u679c\u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1317\" height=\"473\" src=\"https:\/\/cdn.artru.eu.org\/wp-content\/uploads\/2023\/07\/Convert-GitHub-to-raw-githack.png\" alt=\"\u5c06 GitHub \u8f6c\u6362\u4e3a raw.githack\" class=\"wp-image-1342\"\/><figcaption class=\"wp-element-caption\">\u5c06 GitHub \u8f6c\u6362\u4e3a raw.githack<\/figcaption><\/figure>\n<\/div>\n\n\n<p><strong>1. \u7528\u4e8e\u4e3b\u7f51\u7ad9\u3002<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6ca1\u6709\u6d41\u91cf\u9650\u5236\u3002\u6587\u4ef6\u901a\u8fc7 CloudFlare \u7684 CDN \u63d0\u4f9b\u3002<\/li>\n\n\n\n<li>\u5982\u679c\u6dfb\u52a0\uff0c\u6587\u4ef6\u53ef\u4ee5\u81ea\u52a8\u538b\u7f29\u4e3a .min \u6587\u4ef6&nbsp;<code data-no-translation=\"\" data-no-auto-translation=\"\">?min=1<\/code> \u5728\u67e5\u8be2\u53c2\u6570\u7684\u672b\u5c3e\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\" data-no-translation=\"\" data-no-auto-translation=\"\"><code data-no-translation=\"\" data-no-auto-translation=\"\">https:&#47;&#47;rawcdn.githack.com\/jquery\/jquery\/4a13266efd262a92f05d86b71d715885de103e6d\/src\/core.js<\/code><\/pre>\n\n\n\n<p><strong>2. \u5f00\u53d1\u73af\u5883\u4e2d\u4f7f\u7528<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\" data-no-translation=\"\" data-no-auto-translation=\"\"><code data-no-translation=\"\" data-no-auto-translation=\"\">https:&#47;&#47;raw.githack.com\/jquery\/jquery\/main\/src\/core.js<\/code><\/pre>\n\n\n\n<p>\u60a8\u63a8\u9001\u7684\u65b0\u66f4\u6539\u5c06\u5728\u51e0\u5206\u949f\u5185\u53cd\u6620\u51fa\u6765\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5f97\u51fa\u7ed3\u8bba<\/h2>\n\n\n\n<p>\u901a\u8fc7\u4f7f\u7528\u8fd9\u4e9b\u670d\u52a1\uff0c\u60a8\u53ef\u4ee5\u7b80\u5355\u6709\u6548\u5730\u5229\u7528 GitHub \u4f5c\u4e3a\u60a8\u7f51\u7ad9\u7684 CDN\u3002<\/p>\n\n\n\n<p>\u4e0d\u8fc7\uff0c\u60a8\u8fd8\u5e94\u8be5\u6ce8\u610f\uff0c\u8fd9\u4e9b\u514d\u8d39\u7684 CDN \u670d\u52a1\u5e76\u4e0d\u80fd\u4fdd\u8bc1\u60a8\u7684\u5185\u5bb9\u7684\u7a33\u5b9a\u6027\u548c\u5b89\u5168\u6027\uff0c\u56e0\u6b64\u5728\u5c06\u5b83\u4eec\u7528\u4e8e\u91cd\u8981\u6216\u5546\u4e1a\u7f51\u7ad9\u4e4b\u524d\uff0c\u60a8\u5e94\u8be5\u4ed4\u7ec6\u8003\u8651\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u60a8\u5bf9\u5982\u4f55\u4f7f\u7528 GitHub \u4f5c\u4e3a\u7f51\u7ad9\u7684 CDN \u6709\u4efb\u4f55\u7591\u95ee\uff0c\u8bf7\u5728\u4e0b\u9762\u53d1\u8868\u8bc4\u8bba\u3002\u795d\u4f60\u597d\u8fd0\uff01 \ud83d\ude0a<\/p>","protected":false},"excerpt":{"rendered":"<p>CDN l\u00e0 g\u00ec? CDN (Content Delivery Network) l\u00e0 m\u1ed9t m\u1ea1ng l\u01b0\u1edbi ph\u00e2n ph\u1ed1i n\u1ed9i dung, gi\u00fap t\u0103ng t\u1ed1c \u0111\u1ed9 t\u1ea3i trang web b\u1eb1ng c\u00e1ch l\u01b0u tr\u1eef c\u00e1c t\u1ec7p tin t\u0129nh [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1338,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-1294","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-website"],"_links":{"self":[{"href":"https:\/\/artru.net\/zh\/wp-json\/wp\/v2\/posts\/1294","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/artru.net\/zh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/artru.net\/zh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/artru.net\/zh\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/artru.net\/zh\/wp-json\/wp\/v2\/comments?post=1294"}],"version-history":[{"count":0,"href":"https:\/\/artru.net\/zh\/wp-json\/wp\/v2\/posts\/1294\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/artru.net\/zh\/wp-json\/wp\/v2\/media\/1338"}],"wp:attachment":[{"href":"https:\/\/artru.net\/zh\/wp-json\/wp\/v2\/media?parent=1294"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/artru.net\/zh\/wp-json\/wp\/v2\/categories?post=1294"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/artru.net\/zh\/wp-json\/wp\/v2\/tags?post=1294"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}