标签:
The Network panel records information about each network operation in your application, including detailed timing data, HTTP request and response headers, cookies, WebSocket data, and more. The Network panel helps you answer questions about the network performance of your web application, such as:
The Network panel uses the Resource Timing API, a JavaScript API that provides detailed network timing data for each loaded resource. For example, the API can tell you precisely when the HTTP request for an image started, and when the image‘s final byte was received. The following illustration shows the network timing data points that the Resource Timing API provides.
The API is available to any web page, not just DevTools. In Chrome, it‘s exposed as methods on the globalwindow.performance
object. The performance.getEntries()
method returns an array of "resource timing objects", one for each requested resource on the page.
Try this: open the JavaScript console on the current page, enter the following at the prompt, and hit Return:
window.performance.getEntries()[0]
This evaluates the first element in the array of resource timing objects and displays its properties in the console, as shown below.
Each timestamp is in microseconds, following the High ResolutionTime specification. This API is available inChrome as the window.performance.now()
method.
The Network panel automatically records all network activity while DevTools is open. The first time you open the panel it may be empty. Reload the page to start recording, or simply wait for network activity to occur in your application.
Each requested resource is added as a row to the Network table, which contains the columns listed below. Note the following about the Network table:
By default, the current network record log is discarded when you navigate to another page, or reload the current page. To preserve the recording log in these scenarios, click the black Preserve log upon navigationbutton at the bottom of the Network panel; new records are appended to the bottom of the table. Click the same button again (now red ) to disable log preservation.
By default, resources in the Network table are sorted by the start time of each request (the network "waterfall"). You can sort the table by another column value by clicking the column header. Click the header again to change the sort order (ascending or descending).
The Timeline column is unique from the others in that, when clicked, it displays a menu of additional sort fields.
The menu contains the following sorting options:
To filter the Network table to only show certain types of resources, click one of the content types along the bottom of the panel: Documents, Stylesheets, Images, Scripts, XHR, Fonts, WebSockets, and Other. In the following screenshot only CSS resources are shown. To view all content types, click the All filter button.
In addition to resource type filtering, you can narrow down resources by filter queries. For example, to find all resources which have a status code of 200
, you can enter the query StatusCode:200
in the filter input field.
Take note of the following behaviour: A filter query includes a type (StatusCode
) and value (200
). A filter query is case insensitive, so you can type uppercase or lowercase. The filter type gives you autocomplete suggestions. Use the arrows keys to form a selection and press Tab to select it. The filter value has autocomplete which shows you values present in the current network recording. Quickly preview the results of your query, use the Up / Down arrow keys to cycle through the autocomplete suggestions. The results appear immediately even you do not press enter or tab to complete the selection. To negate a filter query, prepend the query with a dash (-
), for example -StatusCode:200
.
Available filter types:
www.google-analytics.com
.Access-Control-Allow-Origin
.running
k
) & megabyte (m
) units also allowed: E.g.larger-than:50
, larger-than:150k
, larger-than:2m
GET
.Content-type
- the identifier for the type of resource. E.g.text/html
.https
.loggedIn
(assuming a cookie like loggedIn=true
).true
(assuming a cookie likeloggedIn=true
).foo.com
(assuming a cookie like loggedIn=true; Domain=foo.com; Path=/; Expires=Wed, 13 Jan 2021 22:23:01 GMT; HttpOnly
).200
.To use a query shown in the above list, construct it in the format of: <Filter Type>:<Description>
. You will almost always want to use the autocomplete suggestions which ensures your query is valid.
You can change the default set of columns displayed by the Network table. To show or hide a column, Right+click or Control+click (Mac only) in the table header and select or deselect column names from the list.
You can view the Network table with large resource rows (the default), or small resource rows. Click the blueUse small resource rows toggle button at the bottom of the panel to view small rows. Click the same button (now gray ) to view large resource rows again. Large rows enable some columns to display two text fields: a primary field and a secondary field (Time and Latency, for instance). When viewing small rows only the primary field is displayed.
The network table with small resource rows and just the timeline column.
The waterfall view in the network panel graphs the time it took to load each resource.From the start of the HTTP request to the receipt of the final byte of the response.
Each resource loading time is represented as a bar.This has color-coded information related to each resource.Each color specifies a different step needed to recieve the resource.The larger the bar grows represents more data being trasmitted for the request.
The network timeline for a simple web page.
Hovering your mouse over the bar itself will present the complete timing data.This is the same information that‘s presented in the Timing details tab for a given resource.
Network timing details revealed on hover.
The waterfall highlights DOMContentLoaded
and load
events display with blue and red vertical lines. When the engine has completed parsing of the main document the DOMContentLoaded
event fires. Upon retrieving all the page‘s resources the load
event will fire.
The event lines as displayed over the timeline.
You may enable in the network settings to view the timeline as color-coded by resource type.If you do the network timing information is still accessible through the tooltip.Waterfall bars are color-coded as follows:
Documents | |
Stylesheets | |
Images | |
Scripts | |
XHR | |
Fonts | |
Other |
Right-clicking or Ctrl + Click (Mac only) within the Network table a context menu appears with several actions. Some of these actions apply to the resource row under the mouse click (like copying HTTP request headers), while others apply to the entire network recording (such as saving a Network recording as a HAR file).
The following menu actions apply to the selected resource:
cURL is a command line tool for making HTTP transactions. The Network panel‘s Copy as cURL command recreates an HTTP request (including HTTP headers, SSL certificates, and query string parameters) and copies it as a cURL command string to the clipboard. You can then paste the string into a terminal window (on a system with cURL) to execute the same request.
Below is an example cURL command line string taken from a XHR request on the Google News home page.
curl ‘http://news.google.com/news/xhrd=us‘ -H ‘Accept-Encoding: gzip,deflate,:sdch‘ -H ‘Host: news.google.com‘ -H ‘Accept-Language: en-US,en;q=0.8‘ -H ‘User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1510.0 Safari/537.36‘ -H ‘Accept: */*‘ -H ‘Referer: http://news.google.com/nwshp?hl=en&tab=wn‘ -H ‘Cookie: NID=67=eruHSUtoIQA-HldQn7U7G5meGuvZOcY32ixQktdgU1qSz7StUDIjC_Knit2xEcWRa-e8CuvmADminmn6h2_IRpk9rWgWMdRj4np3-DM_ssgfeshItriiKsiEXJVfra4n; PREF=ID=a38f960566524d92:U=af866b8c07132db6:FF=0:TM=1369068317:LM=1369068321:S=vVkfXySFmOcAom1K‘ -H ‘Connection: keep-alive‘ --compressed
You can save the data from a network recording as a HAR (HTTP Archive) file, or copy the records as a HAR data structure to your clipboard. A HAR file contains a JSON data structure that describes the network "waterfall". Several third-party tools can reconstruct the network waterfall from the data in the HAR file.
To save a recording:
For more information, Web Performance Power Tool: HTTP Archive (HAR).
When you click a resource name in the Network table a tabbed window appears that contains the following additional details:
The Headers tab displays the resource‘s request URL, HTTP method, and response status code. Additionally, it lists the HTTP response and request headers and their values, and any query string parameters. You can view HTTP headers parsed and formatted, or in their source form by clicking the View parsed/View source toggle button, respectively, located next to each header‘s section. You can also view parameter values in their decoded or URL encoded forms by clicking the View decoded/View URL encoded toggle button next to each query string section.
You can also copy request and response headers to your clipboard.
The Preview tab displays a preview of the resource, when available. Previews are currently displayed for image and JSON resources, as shown below.
You can view the resource‘s unformatted response on the Responsetab.
The Response tab contains the resource‘s unformatted content. Below is a screenshot of a JSON data structure that was returned as the response for a request.
You can also view formatted previews of some resource types, including JSON data structures and images.
The Cookies tab displays a table of all the cookies transmitted in theresource‘s HTTP request and response headers. You can also clear all cookies.
The Cookies table contain the following columns:
The Frames tab shows messages sent or received over a WebSocket connection. This tab is only visible when the selected resource initiated a WebSocket connection. The table contains the following columns:
Messages are color-coded according to their type. Outgoing text messages are color-coded light-green; incoming text messages are white:
WebSocket opcodes are light-yellow:
Errors are light-red.
Notes about current implementation:
The Timing tab graphs the time spent on the various network phases involved loading the resource. This is the same data displayed when you hover over a resource bar in the waterfall view.
To learn more optimizing the network performance of your application, see the following resources:
【转载】https://developers.google.com/web/tools/profile-performance/network-performance/resource-loading
https://developer.chrome.com/devtools/docs/network#resource-previews
标签:
原文地址:http://www.cnblogs.com/julin-peng/p/4812793.html