GitGraph JS not loading from CDN

别来无恙 提交于 2019-12-23 03:01:58

问题


I'm trying to get GitGraph working and producing a GitFlow-like graph for a document I'm putting together.

Here's my HTML file:

<html>
  <head>
    <title>GitFlow</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/gitgraph.js/1.11.4/gitgraph.min.css"></script>
    <script>
      var gitgraph = new GitGraph({
        template: "blackarrow",
        reverseArrow: false,
        orientation: "horizontal",
        mode: "compact"
      });
    </script>
    <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/gitgraph.js/1.11.4/gitgraph.css" />
  </head>
  <body>
    <canvas id="gitGraph"></canvas>
  </body>
</html>

When I open this in a browser I just get an empty/blank page. In Chrome Dev console I see the following error:

Uncaught ReferenceError: GitGraph is not defined
at gitgraph.html:6

So for some reason its not pulling in GitGraph from the CDN. Can anybody spot where I'm going awry?


回答1:


Got it working with this:

<html>
  <head>
    <title>GitFlow</title>
    <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/gitgraph.js/1.11.4/gitgraph.css" />
  </head>
  <body>
    <canvas id="gitGraph"></canvas>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/gitgraph.js/1.11.4/gitgraph.min.js"></script>
    <script>
      var gitgraph = new GitGraph({
        template: "blackarrow",
        reverseArrow: false,
        orientation: "horizontal",
        mode: "compact"
      });

      gitgraph.branch().commit().commit();
    </script>
  </body>
</html>



回答2:


This

<script src="https://cdnjs.cloudflare.com/ajax/libs/gitgraph.js/1.11.4/gitgraph.min.css"></script>

is loading the css file. You can validate it from the file extension.

It need to be

<script src="https://cdnjs.cloudflare.com/ajax/libs/gitgraph.js/1.11.4/gitgraph.min.js"></script>


来源:https://stackoverflow.com/questions/48106879/gitgraph-js-not-loading-from-cdn

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!