A curious developer, eh? Kudos to you for digging into Instagram's network requests using Inspect Element (DevTools)! I'll help you understand what's going on.
The mystery:
You're expecting to see feed data (e.g., posts, images, captions) in the Network requests, but there's seemingly nothing related to the feed. Yet, your Instagram feed loads just fine. How is this possible?
The culprit: Modern web optimization techniques
Instagram (and many other modern web apps) employ various optimization techniques to improve performance, reduce latency, and enhance user experience. Here are the key players in this mystery:
- Server-Side Rendering (SSR): Instagram's initial HTML is generated on the server, including the basic structure and some initial data (e.g., user info, config). This is why you see some initial requests (e.g.,
index.html, manifest.json) in the Network tab.
- JavaScript-heavy frontend: Instagram's frontend is built using React (a popular JavaScript library). The React app takes over after the initial HTML is loaded. It dynamically fetches, processes, and renders the feed data in-memory, without causing full page reloads.
- JSON data embedded in HTML: During SSR, Instagram embeds some initial JSON data directly into the HTML using a
<script> tag. This technique is called "inlined data" or "bootstrapped data". You'll find a <script> tag with a huge JSON blob in the HTML response ( inspect the HTML in DevTools > Elements tab). This JSON contains initial feed data, user info, and other essential info.
- GraphQL & Incremental Data Fetching: When you scroll down, Instagram's React app makes incremental GraphQL requests (small, targeted queries) to fetch additional feed data, without reloading the entire page. These requests are not visible as separate "feed data" requests in the Network tab (more on this below).
Why you don't see feed data requests:
Here's the magic:
- The initial feed data is already embedded in the HTML (in that huge JSON
<script> tag). Your browser doesn't need to make an additional request for this data.
- Incremental feed data is fetched using GraphQL queries, which are:
- Sent as POST requests to a single endpoint (
/graphql/query/ or similar). These requests are not labeled as "feed data" or anything obvious.
- Contain query payloads (JSON) with specific query names (e.g.,
FeedGridContainerQuery, FeedUnitPaginationContainerQuery). These payloads are not easily recognizable as "feed data" either.
- Return small, chunked responses (10-20 posts at a time) in JSON format, which are then processed in-memory by React. No full page reload occurs.
In the Network tab, you'll see requests like:
graphql/query/ (POST) with a JSON payload containing the query name (e.g., FeedGridContainerQuery)
batchFetch or query (POST) with a JSON payload containing multiple queries (including feed-related ones)
These requests don't explicitly say "feed data", but they do contain the incremental feed data. To spot them:
- Open DevTools > Network tab.
- Filter requests by method: POST and Domain: instagram.com (or
www.instagram.com).
- Look for requests with JSON payloads containing query names starting with
Feed (e.g., FeedGridContainerQuery).
Inspect the requests:
- Click on one of those
graphql/query/ requests.
- In the Request panel (right-side panel), inspect the Request Payload (JSON). You'll see the query name and variables (e.g.,
feedUnitId, count, after).
- In the Response panel, inspect the Response Data (JSON). You'll see the actual feed data (edges, nodes, posts) wrapped in GraphQL's verbose syntax.
Bonus tip:
To beautify the JSON responses and make them easier to read:
- Install the JSONView extension (Chrome, Firefox).
- Reload the Instagram page.
- Inspect the
graphql/query/ requests again. JSONView will format the responses nicely.
Now, go forth and inspect those Instagram requests like a pro!
Recap:
- Initial feed data is embedded in HTML via SSR.
- Incremental feed data is fetched using GraphQL queries (POST requests) with JSON payloads.
- These requests are not explicitly labeled as "feed data" but contain the necessary data.
- Use DevTools filters (method: POST, domain) and inspect JSON payloads & responses to spot the feed data.
Happy debugging!