Chrome Dev Tools - "Size" vs "Content" - google-chrome

When viewing information about stylesheets in the Network tab of Chrome's dev tools, one column specifies both "size" and "content":
Can anybody shed light on the difference between these two numbers? On some pages the numbers are close and others they are different by a considerable amount.

"Size" is the number of bytes on the wire, and "content" is the actual size of the resource. A number of things can make them different, including:
Being served from cache (small or 0 "size")
Response headers, including cookies (larger "size" than "content")
Redirects or authentication requests
gzip compression (smaller "size" than "content", usually)
From the docs:
Size is the combined size of the response headers (usually a few
hundred bytes) plus the response body, as delivered by the server.
Content is the size of the resource's decoded content. If the resource
was loaded from the browser's cache rather than over the network, this
field will contain the text (from cache).

Size is the size of response itself, and Content is the size of resource, that you are accessing.
Compare:
empty cache:
main.js GET 200 OK .. Size: 31.72KB Content: 31.42KB
cached:
main.js GET 304 Not modified .. Size: 146B Content: 31.42KB

In simple terms Google article explain it as
Size = Transfer size and Content = Actual size
This is my formula based on reading various articles on this topic (and I am open to improve it further with your comments)
Size = Compression(Content) + Response Header
See the image used in this article
Explanation by Google

"Use large request rows" to show both values!
If you don't see the second value (content) you need to click the "Use large request rows" button inside Chrome Network tab:
I found this thanks to the answer on this question here:
Chrome Devs tools - where's size and content?

Size includes response AND request info
Size is a sum of:
bytes transferred for the request header
bytes transferred for the response header
bytes transferred for the response body
From the docs:
Inspecting the properties of an individual resource, such as its HTTP headers [note the plural, emphasis mine], content, size, and so on.
If you compare the transferSize of a performanceEntry (e.g. for the main document at https://stackoverflow.com/) with the Size in Chrome DevTools' Network tab, you'll see that the two don't match up. That is because the performanceEntry doesn't contain the size of the request header.
Screenshot of the Network tab and a logged performance entry

Related

Download of brotli compressed file: Chrome vs Firefox

Imagine this simple snippet that fetches a file:
const xhr = new XMLHttpRequest()
xhr.onprogress = event => {
console.log(`Progress: ${event.loaded}/${event.total}`)
}
xhr.open('GET', 'https://example.com/myfile.data.br')
xhr.send()
The file is brotli compressed, and served with the following response headers:
content-encoding: br
content-length: 13934674
According to the network tab, 13.94 MB gets transfered when fetching this file, and the resource size is 30.30 MB.
This is what Firefox' console looks like:
As you can see, it's respects the content-length, and is actually able to report progress on it.
This is what Chrome's console looks like:
Notice how both the event.loaded and event.total is different. Chrome seems to report progress on the actually resource size (not the compressed size!), but it doesn't know the total resource size (which makes sense because it's compressed so it doesn't know what the total resource size will be).
When digging a bit deeper, I actually noticed Chrome is just wrong here. It tells you it downloaded 30.30 MB, but it didn't, it only transferred 13.94 MB.
Even when you fetch this file directly via the browser, it looks like Chrome is fooling you (throttled my network to be able to capture it):
See how it's pretending to be downloading 30.30 MB (it's currently at 21.2 MB), while it's actually only downloading 13.94 MB. My download speed is then calculated based on that uncompressed resource size and the elapsed time, and therefor completely wrong. The blue progress bar is actually not a left-to-right progress bar but rather an animated "I don't know the total" progress bar, I just took my screenshot on this particular moment where it appears to be loaded from left to right, but it's not.
Firefox seems to do it better:
Here, we do have a total, and thus a left-to-right progress bar, and the correct download speed.
My questions:
Is this behavior in Chrome expected?
How to properly implement a progress bar that will work for both?

Origin of iframe when sandbox is enabled without allow-same-origin [duplicate]

As you can see from this Bugzilla thread (and also), Firefox does not always send an Origin header in POST requests. The RFC states that it should not be sent in certain undefined "privacy-sensitive" contexts. Mozilla defines those contexts here.
I'd like to know whether these are the only situations in which Firefox will not send the Origin header. As far as I can tell, it also will not send it in cross-origin POST requests (though Chrome and Internet Explorer will), but I can't confirm that in the documentation. Is it enumerated somewhere that I'm missing?
As far as what the relevant specs actually require, the answer has a couple parts:
When browsers must internally set an origin to a value that’ll get serialized as null
When browsers must send the Origin header
Here are the details:
When browsers must set origin to a value that’ll get serialized as null
The HTML spec uses the term opaque origin and defines it as an “internal value”:
with no serialization it can be recreated from (it is serialized as "null" per ASCII serialization of an origin), for which the only meaningful operation is testing for equality
In other words everywhere the HTML spec says opaque origin, you can translate that to null.
The HTML spec requires browsers to set an opaque origin or unique origin in these cases:
Cross-origin images (including cross-origin img elements)
Cross-origin media data (including cross-origin video and audio elements)
Any document generated from a data: URL
Any iframe with a sandbox attribute that doesn’t contain the value allow-same-origin
Any document programmatically created using createDocument(), etc.
Any document that does not have a creator browsing context
Responses that are network errors
The Should navigation response to navigation request of type from source in target be blocked by Content Security Policy? algorithm returns Blocked when executed on a navigate response
The Fetch spec requires browsers to set the origin to a “globally unique identifier” (which basically means the same thing as “opaque origin” which basically means null…) in one case:
Redirects across origins
The URL spec requires browsers to set an opaque origin in the following cases:
For blob: URLs
For file: URLs
For any other URLs whose scheme is not one of http, https, ftp, ws, wss, or gopher.
But note that just because the browser has internally set an opaque origin—essentially null—that doesn’t necessarily mean the browser will send an Origin header. So see the next part of this answer for details about when browsers must send the Origin header.
When browsers must send the Origin header
Browsers send the Origin header for cross-origin requests initiated by a fetch() or XHR call, or by an ajax method from a JavaScript library (axios, jQuery, etc.) — but not for normal page navigations (that is, when you open a web page directly in a browser), and not (normally) for resources embedded in a web page (for example, not for CSS stylesheets, scripts, or images).
But that description is a simplification. There are cases other than cross-origin XHR/fetch/ajax calls when browsers send the Origin header, and cases when browsers send the Origin header for embedded resources. So what follows below is the longer answer.
In terms of the spec requirements: The spec requires the Origin header to be sent only for any request which the Fetch spec defines as a CORS request:
A CORS request is an HTTP request that includes an Origin header. It cannot be reliably identified as participating in the CORS protocol as the Origin header is also included for all requests whose method is neither GET nor HEAD.
So, what the spec means there is: The Origin header is sent in all cross-origin requests, but it’s also always sent for all POST, PUT, PATCH, and DELETE requests — even for same-origin POST, PUT, PATCH, and DELETE requests (which by definition in Fetch are actually “CORS requests” — even though they’re same-origin).*
The other cases when browsers must send the Origin header are any cases where a request is made with the “CORS flag” set — which, as far as HTTP(S) requests, is except when the request mode is navigate, websocket, same-origin, or no-cors.
XHR always sets the mode to cors. But with the Fetch API, those request modes are the ones you can set with the mode field of the init-object argument to the fetch(…) method:
fetch("http://example.com", { mode: 'no-cors' }) // no Origin will be sent
Font requests always have the mode set to cors and so always have the Origin header.
And for any element with a crossorigin attribute (aka “CORS setting attribute”), the HTML spec requires browsers to set the request mode to cors (and to send the Origin header).
Otherwise, for embedded resources — any elements having attributes with URLs that initiate requests (<script src>, stylesheets, images, media elements) — the mode for the requests defaults to no-cors; and since those requests are GET requests, that means, per-spec, browsers send no Origin header for them.
When HTML form elements initiate POST requests, the mode for those POSTs also defaults to no-cors — in the same way that embedded resources have their mode defaulted to no-cors. However, unlike the no-cors mode GET requests for embedded resources, browsers do send the Origin header for those no-cors mode POSTs initiated from HTML form elements.
The reason for that is, as mentioned earlier in this answer, browsers always send the Origin header in all POST, PUT, PATCH, and DELETE requests.
Also, for completeness here and to be clear: For navigations, browsers send no Origin header. That is, if a user navigates directly to a resource — by pasting a URL into a browser address bar, or by following a link from another web document — then browsers send no Origin header.
* The algorithm in the Fetch spec that requires browsers to send the Origin header for all CORS requests is this:
To append a request Origin header, given a request request, run these steps:
1. Let serializedOrigin be the result of byte-serializing a request origin with request.
2. If request’s response tainting is "cors" or request’s mode is "websocket", then
    append Origin/serializedOrigin to request’s header list.
3. Otherwise, if request’s method is neither GET nor HEAD,
    then: [also send the Origin header in that case too]
Step 2 there is what requires the Origin header to be sent in all cross-origin requests — because all cross-origin requests have their response tainting set to "cors".
But step 3 there requires the Origin header to also be sent for same-origin POST, PUT, PATCH, and DELETE requests (which by definition in Fetch are actually “CORS requests” — even though they’re same-origin).
The above describes how the Fetch spec currently defines the requirements, due to a change that was made to the spec on 2016-12-09. Up until then the requirements were different:
  •  previously no Origin was sent for a same-origin POST
  •  previously no Origin was sent for cross-origin POST from a <form> (without CORS)
So the Firefox behavior the question describes is what the spec previously required, not what it currently requires.
For me this was happening on a super-standard form POST to a relative URL on localhost, and seems to have been triggered by having
<meta name="referrer" content="no-referrer">
in the <head>.
Changing it to
<meta name="referrer" content="same-origin">
seemed to make Firefox happier.

Why still make conditional GET (304) with with expires header

I'm learning about web performance.
And as I know, when make request to require a resource with header: "expires" or "cache-control" that still valid, the browser'll not make a conditional GET to ask server if a resource has been modified.
So, why the browser alway make conditional GET when i make this request: https://www.debian.org/Pics/debian.png
screeshot request information
Take a close look at the request headers: "Cache-Control: max-age=0".
When refreshing an URL, your browser always adds this header to make sure it's "refreshed". If you want to see your real browser's behavior, try navigating to another url then click the back button, Chrome should get the image from its cache.
I've just tried, it does!

slow download speed with rendered html

My page request content data after html loaded, it take 2 second for completed show page.
When i set all data in one html(server side rendering) and size 485KB,
it take 4 second to show the page.
Why a 485KB size html load time slow than a 1.6MB json?
My server:
a self-host console server.
Owin & RazorEngine for html pages,
WebAPI for json data.
My 2 web page:
1.
html, just static file,
use ajax(WebAPI) request json data.
2.
Set all data in html, server side rendering.
--07/27 18:21 edit
*old title: Why small index html slow than a big json
I do some more test:
*All contents finally are all same.
1. html + webapi request content.
2. html + render content at server.
3. html with content,render nothing.
4. use webapi get html with content no gzip.
5. just for compare, stackoverflow has more waiting time, less download time.This is what i want.
Looks like the problem is RazorEngine.
Rendered html download speed slower than static file.
How do i fix this?
--07/28 10:38 edit
Just find out what problem is.
It's not RazorEngine's problem,the problem is gzip.
Some big html(977KB) use gzip(69KB) download speed faster(1.95s) than raw html(7.80s),
but sometimes gziped html download speed slower than raw html (third img).
I set file size over 100kb to use gzip, but download speed still not stable.
Is there other problem i not found?
Because when HTML is loaded, it also needs time for rendering on the browser depending upon the content. Thus, the time taken is more.

Schemeless URL valid in HTTP?

Are schemeless urls like
//blog.flowl.info/
valid in HTTP (rfc?), like in plain HTTP Requests and Responses, or are they only valid in HTML attributes and content ?
HTTP/1.1 302 - Moved
Location: //blog.flowl.info
GET //blog.flowl.info
Update:
I have two contradictionary answers now. Which is correct?
Sidequestion:
Why does the browser even resolve those to:
//blog.flowl.info/
->
http://blog.flowl.info/
instead of:
//blog.flowl.info/
->
http://blog.flowl.info///blog.flowl.info/
They are valid in the Location header field (http://greenbytes.de/tech/webdav/rfc7231.html#header.location).
They are not valid in the request line of an HTTP request.
The browser resolves it this way because this is how relative reference resolution works (http://greenbytes.de/tech/webdav/rfc3986.html#reference-resolution).
As far as I understand protocol/scheme is a mandatory part of an URL and is used by server and intermediate proxies/gateways etc to infer how to handle communication on top of plain TCP/IP. If you are not using http/https but some other well known or even custom protocol, you will have to specify it.
Browser was created for browsing html pages served over HTTP protocol. Hence if you don't specify scheme it automatically defaults it as http. There is also concept of absolute v/s relative URL that you will need to look into how subsequent URLs are resolved by browser.