如何在Dropbox中托管网站时使用CDN?

时间:2014-04-19 13:54:49

标签: jquery dropbox cdn

我尝试使用示例jquery-mobile页面如下:

<!DOCTYPE html> 
<html> 
<head> 
    <title>My Page</title> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
    <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
</head> 
<body> 

<div data-role="page">

    <div data-role="header">
        <h1>My Title</h1>
    </div><!-- /header -->

    <div data-role="content">   
        <p>Hello world</p>      
    </div><!-- /content -->

</div><!-- /page -->

</body>
</html>

将此文件作为~/Dropbox/Public/index.html托管在我的Dropbox公用文件夹中。

当我尝试在本地访问该文件时(例如file:///home/<USER>/Dropbox/Public/index.html),一切正常。

当我尝试使用公共链接(例如https://dl.dropboxusercontent.com/u/<DROPBOX_ID>/index.html)访问该文件时,它不会提取jquery文件并且页面显示不正确。此问题并非特定于jquery,也存在于任何其他CDN中。

我可以将文件下载到我的本地计算机并将它们托管在Dropbox中(例如file:///home/<USER>/Dropbox/Public/js/)并且它按预期工作但我想使用CDN不浪费Dropbox带宽并且还能够轻松升级库版本。

有没有办法解决这个问题?

1 个答案:

答案 0 :(得分:2)

您的浏览器可能拒绝将非安全内容(jquery)加载到从安全位置(您的Dropbox托管页面)提供的页面中

将jquery链接更改为使用https,您应该没问题(或者使用procotol相对链接(//code.jquery.com),浏览器将根据需要选择http或https。

相关问题