当前位置:首页 > CN2资讯 > 正文内容

media test failure 服务器 服务器checking media

9小时前CN2资讯


开这个博客的初衷主要是想沉淀一下我最近即将开展的对于HTML5及移动端性能方面的一些探索,而appcache我们更加关注的是缓存策略上对于性能的优化上的帮助,所以对于appcache的运行过程我们需要更加地清楚,昨天的Application Cache API (一)整体介绍了一下appcache,接下来会对appcache做一些黑盒测试,以便我们了解更多。

  这个demo中主要涉及到3类资源,两个页面,我们观察3类资源在不同的场景下浏览器的appcache策略。

 demo代码:

    test1.html如下:





<html manifest="manifest.appcache"> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"> <title>demo</title> </head> <script type="text/javascript" src="js/index.js"></script> <script type="text/javascript"> applicationCache.onchecking = function(){ console.log("checking") } applicationCache.ondownloading = function(){ console.log("dowload") } applicationCache.onnoupdate = function(){ console.log("noupdate") } applicationCache.onprogress = function(){ console.log("progress") } applicationCache.oncached = function(){ console.log("cached") } applicationCache.onupdateready = function(){ console.log("updateready") } applicationCache.onobsolete = function(){ console.log("obsolete") } applicationCache.onerror = function(){ console.log("error") } </script> <link rel="stylesheet" type="text/css" href="css/index.css" media="all" /> <body>   <div id="test">此处观察样式效果<div> <img src="img/index.jpg" /> <img src="img/no-cache.jpg"> </body> </html>





  test2.html如下:





<html <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"> <title>demo</title> </head> <script type="text/javascript" src="js/index.js"></script> <script type="text/javascript"> applicationCache.onchecking = function(){ console.log("checking") } applicationCache.ondownloading = function(){ console.log("dowload") } applicationCache.onnoupdate = function(){ console.log("noupdate") } applicationCache.onprogress = function(){ console.log("progress") } applicationCache.oncached = function(){ console.log("cached") } applicationCache.onupdateready = function(){ console.log("updateready") } applicationCache.onobsolete = function(){ console.log("obsolete") } applicationCache.onerror = function(){ console.log("error") } </script> <link rel="stylesheet" type="text/css" href="css/index.css" media="all" /> <body>   <div id="test">此处观察样式效果<div> <img src="img/index.jpg" /> <img src="img/no-cache.jpg"> </body> </html>





  • 我们在两个页面中对于applicationCache对象的事件进行了监听,并将当前触发的事件名输出到console中,以便我们了解发生了什么
  • 两者区别在于,一个引用了manifest,一个没有,用于进行对比。
  • js和css初始化为空,用于观察效果



 

结论及场景

  1, application cache并不因服务器上资源改变而改变,只有manifest改变才会触发重新download,并且是所有cache文件均重新获取

    正常载入test1.html时,console输出如下:



checking /html5/appcache/:13 noupdate /html5/appcache/:37



          当js,css和图片发生变化时,载入test1.html ,console不变:



checking /html5/appcache/:13 noupdate /html5/appcache/:37



   当manifest文件进行修改后,console如下:


checking /html5/appcache/:13 dowload /html5/appcache/:27 5 progress /html5/appcache/:49 updateready /html5/appcache/:67



 

  2,对于另一个没有引用manifest文件的html,当它加载时,不会触发applicationCache的任何事件,但是会使用缓存。

  页面加载的时候。console输入为空

  修改服务器js,css等资源,页面中没有变化,修改manifest文件后,刷新页面,资源修改的效果出现。

  

  3,直接请求资源的绝对路径,只要该url被缓存过,那么所有的访问均是该资源的缓存,而与引用所在的宿主页面是否有manifest没有关系

  给js中写上alert("更新"),访问该资源的url,结果没有变化

  更新manifest之后,该js的访问得到更新

 

       4,js和css,图片文件的本身的访问,均会进行checking

  直接在地址栏输入一个缓存的js文件,console显示如下:


Document was loaded from Application Cache with manifest http://localhost/html5/appcache/manifest.appcache Application Cache Checking event Application Cache NoUpdate event



  

  修改manifest文件后,再次访问这个资源。显示如下:





Document was loaded from Application Cache with manifest http://localhost/html5/appcache/manifest.appcache Application Cache Checking event Application Cache Downloading event Application Cache Progress event (0 of 4) http://localhost/html5/appcache/css/index.css Application Cache Progress event (1 of 4) http://localhost/html5/appcache/js/index.js Application Cache Progress event (2 of 4) http://localhost/html5/appcache/ Application Cache Progress event (3 of 4) http://localhost/html5/appcache/img/index.jpg Application Cache Progress event (4 of 4) Application Cache UpdateReady event





     所有的资源,均被重新下载

 

  经过反复试验后,我们可以总结出以下浏览器在应用缓存方面处理url的逻辑策略:

  

 

    你可能想看:

    扫描二维码推送至手机访问。

    版权声明:本文由皇冠云发布,如需转载请注明出处。

    本文链接:https://www.idchg.com/info/31935.html

    分享给朋友:

    “media test failure 服务器 服务器checking media” 的相关文章

    BT开心版:简化Linux服务器管理的最佳工具

    BT开心版是一个强大的Linux服务器管理工具,致力于简化网站的搭建、管理和维护过程。对于那些刚接触Linux操作系统的用户来说,BT开心版的出现无疑是一大福音。它的设计理念是让每个用户无论有多少技术背景,都能高效地管理自己的网页,不必深入学习Linux系统的复杂操作。 首先,我发现BT开心版的最大...

    UCloud服务器性能与安全性的全面评测

    UCloud服务器概述 UCloud是一家专注于云计算服务的公司,提供多样的云服务器选项,适合不同业务需求。它不仅满足基本的计算、存储和网络功能,还在高可用性、高性能和安全性上表现出色。通过细致的产品设计,UCloud确保每一位用户都能在稳定的环境中运作,充分利用其提供的技术优势。 在使用UClou...

    VPS Pro - 理想的虚拟专用服务器解决方案

    什么是 VPS Pro VPS Pro 是一种先进的虚拟专用服务器解决方案,提供用户高度可定制的服务器环境。与传统的共享主机或物理服务器相比,VPS Pro 以虚拟化技术为基础,让每位用户享有像独立服务器一样的资源和灵活性。这种技术不仅提升了资源的利用率,还为用户提供了更高的控制权限。 在VPS P...

    甲骨文云免费IPv6服务详解:轻松配置与应用技巧

    甲骨文云,作为一个综合性的云服务提供商,正迅速崛起于众多的云技术平台之中。它不仅拥有强大的数据处理能力,还提供了多种免费的云服务选项,让个人和企业都能以更低的成本探索并使用云计算的强大功能。首先,我对甲骨文云的快速适应能力和多种灵活服务感到印象深刻,尤其是它的免费套餐项目,吸引了不少用户前来试用。...

    选择和管理海外服务器的最佳策略与优势

    在如今这个信息高度发达的时代,海外服务器逐渐成为许多企业的不二选择。简单来说,海外服务器是指那些位于中国境外的数据处理设备。这些服务器致力于为全球用户提供高效的服务,不论是数据存储、网站托管还是其他在线服务。通过使用海外服务器,企业能够接触到更广阔的市场以及可定制的解决方案,以满足特定需求。 选择海...

    物语云:为游戏行业提供高效安全的云计算解决方案

    物语云概述 物语云是北京物语云联网络科技有限公司旗下的云计算品牌。这一品牌专注于为游戏行业提供一系列数据中心基础服务和互联网业务解决方案,其产品线包括专属服务器租用、云服务器、虚拟主机、服务器托管及带宽租用等。物语云的目标在于为客户提供高效、安全、经济的云计算服务,从而帮助他们在激烈的市场竞争中立足...