Skip to content

Instantly share code, notes, and snippets.

@kfly8
Last active December 21, 2015 15:39
Show Gist options
  • Select an option

  • Save kfly8/6327648 to your computer and use it in GitHub Desktop.

Select an option

Save kfly8/6327648 to your computer and use it in GitHub Desktop.
dataURIだと、リクエストを二回しているように見えるのだけど、これは何でだろうか・・? http://gyazo.com/14be7c5edfeec270a8303be41fa251fe
<!doctype html>
<head>
<meta charset="utf-8">
</head>
<body>
<img id="hoge" />
<script>
var img = new Image();
var src = "https://1.gravatar.com/avatar/918b601dbd1297d58105508fb880b598?d=https%3A%2F%2Fidenticons.github.com%2Fe553551532c5b2c4074cc6c188f1d49<
//var src = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD//gA7Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcgSlBFRyB2NjIpLCBxdWFsaXR5ID0gOTAK/<
var hoge = document.getElementById("hoge");
console.log('before onload');
console.log(window.performance.getEntries());
img.onload = function() {
console.log('img onload');
console.log(window.performance.getEntries());
hoge.src = img.src; // DataUriの時は、ここでもDevTools > Networkに表示されるが、画像パスの時は表示されない
}
hoge.onload = function() {
console.log('hoge onload');
console.log(window.performance.getEntries());
alert('hoge loaded'); // DataUriでも画像パスを指定したときでも、これは呼ばれる
}
img.src = src;
</script>
</body>
</html>
@kfly8

kfly8 commented Aug 24, 2013

Copy link
Copy Markdown
Author

http://www.w3.org/TR/resource-timing/#resources-included

The rest of this section is non-normative.

Examples:

If the same canonical URL is used as the src attribute of two HTML IMG elements, the fetch of the resource initiated by the first HTML IMG element should be included in the PerformanceResourceTiming interface. The user agent might not re-request the URL from the networking layer for the second HTML IMG element, instead using an in-memory browser cache. In this case, there is only a single request sent to the networking layer for retrieval, so the fetch of the resource by the first IMG element would be the only occurrence in the PerformanceResourceTiming interface.

標準の挙動じゃないってところに、ばっちり、
「同じUserAgentで同じパスだったら、2回目のHTML要素では、再びリクエストすることはない。」ってあった。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment