Efficient Techniques for Gathering and Collecting HAR Files- A Comprehensive Guide

by liuqiyue

How to Collect HAR File: A Comprehensive Guide

Collecting a HAR (HTTP Archive) file is an essential step for analyzing and debugging web performance issues. HAR files provide detailed information about the network requests made by a web browser, including request and response times, headers, cookies, and more. This article will guide you through the process of collecting a HAR file, ensuring you have all the necessary information to optimize your website’s performance.

What is a HAR File?

A HAR file is a JSON-formatted file that contains a comprehensive record of all the network activity of a web page. It is generated by browser developer tools, such as Chrome DevTools and Firefox Developer Tools. By analyzing a HAR file, you can identify performance bottlenecks, diagnose issues, and make informed decisions to improve your website’s user experience.

Collecting a HAR File in Chrome DevTools

To collect a HAR file in Chrome DevTools, follow these steps:

1. Open Chrome and navigate to the webpage you want to analyze.
2. Right-click on the webpage and select “Inspect” or press “Ctrl+Shift+I” (Cmd+Option+I on Mac) to open the developer tools.
3. Click on the “Network” tab to view all network requests made by the webpage.
4. Ensure that the “Preserve log” option is checked in the bottom-right corner of the developer tools. This will save the network requests even after you close the tab.
5. Perform actions on the webpage that you want to record, such as clicking links, submitting forms, or scrolling.
6. Once you have finished collecting data, click the “Stop” button in the Network tab.
7. In the Network tab, click on the name of the first request you want to include in the HAR file. This will select all related requests.
8. Right-click on the selected requests and choose “Save as HAR with content…” from the context menu.
9. Save the HAR file to your desired location on your computer.

Collecting a HAR File in Firefox Developer Tools

To collect a HAR file in Firefox Developer Tools, follow these steps:

1. Open Firefox and navigate to the webpage you want to analyze.
2. Press “Ctrl+Shift+I” (Cmd+Option+I on Mac) to open the developer tools.
3. Click on the “Network” tab to view all network requests made by the webpage.
4. Click on the “Start Recording” button in the top-right corner of the developer tools.
5. Perform actions on the webpage that you want to record.
6. Click the “Stop Recording” button when you have finished collecting data.
7. In the Network tab, click on the name of the first request you want to include in the HAR file. This will select all related requests.
8. Right-click on the selected requests and choose “Save as HAR with content…” from the context menu.
9. Save the HAR file to your desired location on your computer.

Using a HAR File to Analyze Web Performance

Now that you have collected a HAR file, you can use it to analyze web performance. Open the HAR file in a text editor or a dedicated HAR analysis tool, such as WebPageTest or HAR Viewer. These tools will provide you with an overview of the performance metrics, including load times, resource sizes, and more. Use this information to identify and fix performance issues, such as slow network requests, excessive redirects, and unnecessary resource loading.

Conclusion

Collecting a HAR file is a valuable step in optimizing your website’s performance. By following the steps outlined in this article, you can easily collect and analyze HAR files to identify and resolve web performance issues. Remember to regularly test and monitor your website’s performance to ensure a smooth and enjoyable user experience.

You may also like