当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 用new Image()预先加载图片真的有用吗?

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 用new Image()预先加载图片真的有用吗?


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-12   浏览: 421 ::
收藏到网摘: n/a

经常会用到在网页上交替显示图片。很多推荐的作法是用new Image() 预先装载图片。但是用new Image()真的有用吗?
试验:
在后台放一个过滤器捕捉所有 /* 的请求:
doFilter里面简单的打印请求的URL:
代码
HttpServletRequest httpRequest = (HttpServletRequest) request;
System.out.println("requets url: " + httpRequest.getRequestURI());
chain.doFilter(request, response);
html代码:
代码
点击运行可以看到效果:
[Ctrl+A 全选 提示:你可先修改部分代码,再按运行]

可以看到打印了三次url。html页面的请求一次。t1.src设值的时候一次。<img src="">的时候一次。
我想这时候如果按按钮改变页面上的图片,应该不会再从服务端载图片了,因为缓存里面已经有了嘛。可是点的时候过滤器仍然是有打印出URL!
看来只要image对象的src一被改变就会发出请求。那预先装载图片不是等于没用吗?