Skip to content
FunnelGuard

Fix guide by FunnelsGuard

Large JSON embedded in HTML: how to find and shrink it

PRF-081Low impactOther toolBy FunnelGuardPublished Updated
On this page

What this issue is

Many sites and apps embed data straight into the HTML so scripts can use it without another request. You see it as <script type="application/json">, window.__INITIAL_STATE__ = {...}, or <script id="__NEXT_DATA__"> on Next.js sites. Page builders, theme settings, product catalogues and tracking setups can all add one.

It becomes a problem when the blob is large (hundreds of KB or more) and the HTML response is not compressed with gzip or Brotli. JSON is repetitive text and usually shrinks a lot when compressed, so sending it raw wastes bandwidth.

Why it costs you leads or sales

The browser must download the whole HTML document before it can finish parsing it. A heavy document delays first paint and the point where forms and buttons work. The effect is mostly felt on mobile and slow networks. The business impact is usually low, but it adds to other weight problems on the same page.

Where the weight hurts
  1. Request pageBrowser asks for the HTML
  2. Download HTML + JSONLarge uncompressed document
  3. Parse and renderStarts late
  4. Form or button usableVisitor may leave first

A large inline blob slows the first step, so every later step starts late.

HTML size before and after compressionExample numbers
HTML size before and after compression (example)Uncompressed: 900 KB; Gzip: 180 KB; Brotli: 140 KB; Brotli + trimmed JSON: 60 KB034569090018014060UncompressedGzipBrotliBrotli + trimmed JSONKB

Example: a 900 KB HTML document with inline JSON often shrinks to a fraction of that with Brotli or gzip. Your numbers will differ.

How to check if your site has it

Check the HTML size and compression
  1. Open DevTools Network

    In Chrome press F12, open the Network tab, reload the page and click the first request (the document).

  2. Compare size and transferred

    In the Size column, the top number is transferred over the network and the bottom is the uncompressed size. If both are about equal and large, the HTML is not compressed.

  3. Check the response headers

    Look for a content-encoding header with gzip or br. If it is missing, compression is off.

  4. Find the blob

    Open View Source and search for application/json, __NEXT_DATA__, __INITIAL_STATE__ or window.. Note which script tag is biggest.

Check compression from the command linebash
curl -s -o /dev/null -D - -H 'Accept-Encoding: br, gzip' https://example.com/ | grep -i content-encoding

# Compare sizes
curl -s https://example.com/ | wc -c
curl -s -H 'Accept-Encoding: gzip' https://example.com/ | wc -c

How to fix it

There are two levers: compress what you send, and send less. Do compression first because it is quick.

Enable compression and trim the data
  1. Turn on compression

    Many hosts and caching plugins have a gzip or Brotli setting. Check your host panel or your caching plugin's settings, or ask your host.

  2. Find the plugin adding the data

    Disable plugins one at a time on a staging site and re-check the HTML size. Page builders and product or map plugins are common sources.

nginx: gzip for HTML and JSONnginx
gzip on;
gzip_comp_level 5;
gzip_min_length 1024;
gzip_types text/html application/json application/javascript text/css image/svg+xml;
Apache: compress HTML and JSONhtaccess
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html application/json application/javascript text/css
</IfModule>

How to confirm it's fixed

Confirmation checks
  • The document response has content-encoding: br or gzip.
  • Transferred size of the HTML is much smaller than its uncompressed size.
  • The biggest inline script tag is smaller, or gone.
  • The page still works: forms, buttons, filters and tracking behave as before.
  • Test on a throttled mobile connection in DevTools (Network > Throttling).

How to prevent it happening again

Prevention
  • Keep compression on for text types at the server or CDN level.
  • Review the HTML size after installing plugins, apps or theme updates.
  • Set a rough size budget for the HTML document and check it in releases.
  • Avoid printing whole objects into the page; pick fields.
  • Load large datasets on demand instead of on first load.

How FunnelGuard handles this

This is outside what FunnelGuard checks. FunnelGuard runs your customer journeys with a robot visitor and checks steps, tracking hits and lead delivery. It does not inspect HTML size, inline JSON or server compression. For this issue use a page speed or performance tool, such as Lighthouse or PageSpeed Insights, or a build-time bundle and size analyser. They report document size and compression.

If a heavy page ever makes a form or button stop working, a FunnelGuard journey check can show that the step failed. It will not tell you the cause is the JSON blob.

Questions people ask

Why is my HTML file so large?

Often because data is embedded inside it, such as an app state script, a product list or builder settings. Open View Source and look for large <script> tags. Inline CSS and SVG can also add weight.

Does inline JSON in HTML hurt performance?

It can. The browser must download the whole document before it finishes parsing, so a large blob delays rendering. It matters most on slow mobile networks and when the HTML is not compressed.

How do I check if my HTML is compressed?

Open DevTools, go to the Network tab, reload, and click the document request. Look for content-encoding: gzip or br in the response headers. You can also run curl -I -H 'Accept-Encoding: br, gzip' yoursite.com.

How do I reduce the size of __NEXT_DATA__?

Return only the props the page needs from getServerSideProps or getStaticProps. Strip unused fields and fetch large lists on the client after load. Make sure the server or CDN compresses the HTML.

Is gzip or Brotli better for HTML?

Brotli usually compresses text slightly better than gzip, and all current browsers support it. Gzip is still a good choice and is widely available. Either is far better than sending HTML uncompressed.

Should I move inline JSON to a separate file?

If the data is not needed for the first screen, yes. A separate file can be cached and loaded later. Small data needed immediately is fine inline.

Can FunnelGuard detect a large JSON payload in my HTML?

No. This is outside what FunnelGuard checks. Use a page speed tool such as Lighthouse or PageSpeed Insights, or a bundle size analyser, for document size and compression.

Does FunnelGuard catch this?

Other tool

Needs a different kind of tool.

Stop finding out from your customers

FunnelGuard runs your real forms and checkouts on a schedule, checks the tracking and the leads behind them, and alerts you once, with a screenshot. Try any paid plan free for 3 days.