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

Javascript
Add a Table to a Word Document
Add Formatted Text to a Word Document
用jscript实现新建word文档
用jscript实现新建和保存一个word文档
Open and Print a Word Document
Use Word to Search for Files
Convert Seconds To Hours
Sample script that deletes a SQL Server database
Sample script that displays all of the users in a given SQL Server DB
firefox中用javascript实现鼠标位置的定位
div+css实现鼠标放上去,背景跟图片都会变化。
Locate a File Using a File Open Dialog Box
Save a File Using a File Save Dialog Box
用jscript实现列出安装的软件列表
List the Stored Procedures in a SQL Server database
Display SQL Server Login Mode
Display SQL Server Version Information
List all the Databases on a SQL Server
用jscript启动sqlserver
Stop SQL Server

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-12   浏览: 422 ::
收藏到网摘: 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一被改变就会发出请求。那预先装载图片不是等于没用吗?