- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
(先发制人:如果您想将此标记为重复项,请注意其他问题似乎在问“为什么我会收到此错误?”我知道为什么会收到此错误;我想知道如何检测我的 JavaScript 代码中的错误。它只出现在 Firebug 控制台中,当然,在加载图像时对用户来说是显而易见的。)
我正在使用 picturefill对于响应图像。我有一个为图像上的加载事件触发的回调。因此,每当有人调整浏览器窗口大小时,回调就会运行,以便通过 picturefill 加载不同的图像。
在回调中,我通过 Canvas 将图像数据转换为 dataURL,这样我就可以将图像数据缓存在 localStorage 中,以便用户即使在离线时也可以使用。
注意关于“离线”的部分。这就是我不能依赖浏览器缓存的原因。而且 HTML5 离线应用程序缓存不能满足我的需求,因为图像是响应式的。 (有关响应式图像与 HTML 离线应用程序缓存不兼容的解释,请参见 "Application Cache is a Douchebag"。)
在 Mac 上的 Firefox 14.0.1 上,如果我将浏览器的大小调整到非常大,然后在大图像有机会完全加载之前再次将其调整回小的大小,加载图像将会触发。它最终会在 Firebug 控制台中报告“图像损坏或被 chop ”,但不会抛出异常或触发错误事件。没有迹象表明代码中有任何错误。就在 Firebug 控制台中。同时,它将 chop 的图像存储在 localStorage 中。
如何在 JavaScript 中可靠且高效地检测到此问题,以便不缓存该图像?
下面是我如何循环遍历 picturefill div 以查找已由 picturefill 插入的 img 标签:
var errorLogger = function () {
window.console.log('Error loading image.');
this.removeEventListener('load', cacheImage, false);
};
for( var i = 0, il = ps.length; i < il; i++ ){
if( ps[ i ].getAttribute( "data-picture" ) !== null ){
image = ps[ i ].getElementsByTagName( "img" )[0];
if (image) {
if ((imageSrc = image.getAttribute("src")) !== null) {
if (imageSrc.substr(0,5) !== "data:") {
image.addEventListener("load", cacheImage, false);
image.addEventListener('error', errorLogger, false);
}
}
}
}
}
下面是 cacheImage()
回调的样子:
var cacheImage = function () {
var canvas,
ctx,
imageSrc;
imageSrc = this.getAttribute("src");
if ((pf_index.hasOwnProperty('pf_s_' + imageSrc)) ||
(imageSrc.substr(0,5) === "data:") ||
(imageSrc === null) || (imageSrc.length === 0)) {
return;
}
canvas = w.document.createElement("canvas");
canvas.width = this.width;
canvas.height = this.height;
ctx = canvas.getContext("2d");
ctx.drawImage(this, 0, 0);
try {
dataUri = canvas.toDataURL();
} catch (e) {
// TODO: Improve error handling here. For now, if canvas.toDataURL()
// throws an exception, don't cache the image and move on.
return;
}
// Do not cache if the resulting cache item will take more than 128Kb.
if (dataUri.length > 131072) {
return;
}
pf_index["pf_s_"+imageSrc] = 1;
try {
localStorage.setItem("pf_s_"+imageSrc, dataUri);
localStorage.setItem("pf_index", JSON.stringify(pf_index));
} catch (e) {
// Caching failed. Remove item from index object so next cached item
// doesn't wrongly indicate this item was successfully cached.
delete pf_index["pf_s_"+imageSrc];
}
};
最后,这是我在 Firebug 中看到的内容的全文,其中 URL 已更改以保护有罪的人:
Image corrupt or truncated: http://www.example.com/pf/external/imgs/extralarge.png
最佳答案
似乎在更改 src
时img
的属性标记,Firefox 触发 load
事件。这与 HTML5 规范相反,即 says如果更改了 src 属性,则应该结束任何其他已经在进行的提取(Firefox 会这样做),并且不应发送任何事件。 load
仅当提取成功完成时才应发送事件。所以我会说你得到一个 load
的事实事件是 Firefox 错误。
但是,图像应该知道它是否完全可用,您可以尝试使用 complete
属性:
if (this.complete === false) {
return;
}
不幸的是,Firefox 有 this.complete
设置为 true
相反,所以这也不是一个选择。
最好的选择可能是创建一个新的 <img>
每次您希望更改元素时 src
属性。
关于javascript - 在 Firefox 中检测到 "image corrupt or truncated",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11928878/
MySQL 似乎允许 TRUNCATE table_name 并且实际上确实截断了表。似乎存在性能差异,TRUNCATE TABLE table_name 似乎更快。我找不到任何关于差异的信息。我发现
我想避免使用 Aerospike 客户端(例如 Python)并使用 native asinfo 从集合中删除记录命令'truncate'因为它可以快速完成。但在我重新启动 Aerospike 后,所
我缺乏构建存储过程的经验,并且遇到了这个错误,我无法理解背后的原因: [2015-09-29 01:01:55] [22001][1292] Data truncation: Truncated in
这个问题很难用短语来表达,所以让我解释一下。 作为 RSS 缓存系统的一部分,我每天多次将大量行插入到数据库中。其中一列是“片段”,用于 RSS 提要中的 description 节点。 有时这个节点
我想我的标题不是那么清楚。 我会试着解释一下: 我可以使用 FileStream 写入和读取文件 FileStream fs = new FileStream("C:\\Users\\Public\\
我正在尝试优化我的批量加载程序。 目前我分步加载数据(我不遵循下面的 SQL 语法,只遵循算法): BEGIN TRUNCATE table COPY into table ANALYZE table
我正在尝试为我的 Minecraft 服务器编写一个商店插件,但每当有人执行/purchase 命令时我总是收到错误消息。 这是错误: 2012-07-03 04:27:28 [SEVERE]
TRUNCATE TABLE 删除表中的所有行,而不记录单个行删除操作。 语法 ?
备注 与 DELETE 语句相比,TRUNCATE TABLE 具有以下优点: 所用的事务日志空间较少。 DELETE 语句每次删除一行,并在事务日志中为所删除的每行记录一个条目。TRUNCA
我最近也遇到了这个问题。当我将表(称为事件和索引)填充到超过 100 万个,并尝试截断它们以进行新测试时,截断后表不为空。 CQL 显示类似 cqlsh> select count(*) from e
如果我尝试截断约 4000 万个文档的大型集合,我会在 arangosh 中超时,并且 arangodb 服务会无响应。留言: arangosh [database_xxx]> db.[collect
我将 spring-data 与 CrudRepository 一起用于任何数据库访问。每天一次,我还必须截断包含大约 100GB 数据的缓存表并重建它。 问题:表被成功截断(我验证表是空的),但是文
这是我正在使用的基于this的sql答案: SET @pattern = '%_movielist'; SELECT concat('TRUNCATE TABLE ', GROUP_CONCAT(co
这是简化的查询。 SELECT `a`, TRUNCATE(`b` / 1000, 3) AS `b` FROM ( ... ) AS `m`
我使用的 MySQL 服务器是 5.5.41。我还想指出,我没有设计这个数据库。 我遇到的问题是,在使用 MySQL 的 TRUCATE 函数时,我似乎因一个错误而中断。因为它不准确。请参阅随附的屏幕
Truncate table语句用来删除/截断表里的所有数据 和delete删除所有表数据在逻辑上含义相同,但性能更快 类似执行了drop table和create table两个语句
前言 上周同事小姐姐问我:“哈哥你看,我发现MySQL有bug,我下午为了清理磁盘,明明删除了100万条MySQL数据,磁盘不仅没有变小,反而更满了呢??” 那你是怎么删除的?
本文主要讲mysql中三种删除表的操作,delete语句、truncate语句以及drop语句的区别: 简介 delete 1、删除整张表的数据: ?
不同点: 1.truncate和delete只删除数据不删除表的结构(定义) drop语句将删除表的结构被依赖的约束(constrain),触发器(trigger),索引(index);依赖于该
SQLite Truncate Table 在SQLite 中,并没有 TRUNCATE TABLE 命令,但可以使用 SQLite 的 DELETE 命令从已有的表中删除全部的数据,但建议使用 D
我是一名优秀的程序员,十分优秀!