【问题标题】:How do you use a cdn to host jQuery?你如何使用 CDN 来托管 jQuery?
【发布时间】:2021-12-21 19:42:55
【问题描述】:

我一直使用jQuery文件来使用jquery。最近我听说使用 CDN。想问一下你是怎么用的,这行代码是干什么的:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>

【问题讨论】:

    标签: jquery cdn


    【解决方案1】:

    内容交付网络CDN 是指一组地理位置分散的服务器,它们协同工作以提供互联网内容的快速交付。

    <!DOCTYPE html>
    <html>
    <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
      $("button").click(function(){
        $("p").hide();
      });
    });
    </script>
    </head>
    <body>
    
    <h2>This is a heading</h2>
    
    <p>This is a paragraph.</p>
    <p>This is another paragraph.</p>
    
    <button>Click me</button>
    
    </body>
    </html>
    

    【讨论】:

      【解决方案2】:

      您是指任何 CDN 还是自己托管? 谷歌有一个 jquery 的 CDN(在这里找到 https://developers.google.com/speed/libraries

      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
      

      【讨论】:

        【解决方案3】:

        这可能对你有帮助:https://code.jquery.com/

        选择你想要的 jQuery 版本(我更喜欢 jQuery3.x 缩小版)。

        当您选择 jQuery 版本(也带有选项)时,您可以复制类似的脚本

        <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
        

        在html中插入脚本&lt;head&gt;:

        ...
        <html>
        <head>
        <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
        </head>
        <body>
        </body>
        </html>
        ...
        

        【讨论】:

          猜你喜欢
          • 2019-04-19
          • 1970-01-01
          • 1970-01-01
          • 2015-04-06
          • 1970-01-01
          • 2019-08-05
          • 2010-12-01
          • 2013-04-26
          • 1970-01-01
          相关资源
          最近更新 更多