Most sites put a search box in the header, so it appears on every page. That is sensible: people expect it. What matters for page weight is not the box itself but what comes with it. A plain search form is a few lines of HTML. A search widget from another company can bring its own scripts, styles and connections, loaded for every visitor on every page, including the many who never search. This article shows how to tell the two apart and how to keep a richer search tool without making everyone download it.
What a plain search box needs
The web already has the parts for search built in. MDN describes <input type="search"> as text fields “designed for the user to enter search queries into”, functionally identical to ordinary text inputs. It notes that q is the most common name for the field, and that without a name nothing is submitted.
Put that field in a form and the browser does the rest. With the default get method, MDN explains, the form data is appended to the action URL with a ? separator, and it recommends get when the form has no side effects, which suits search. Wrapping it in the <search> element marks it as a search landmark for assistive technology; MDN lists the element as widely available across browsers since October 2023.
<search>
<form action="/search/">
<label for="q">Search this site</label>
<input type="search" id="q" name="q">
<button type="submit">Search</button>
</form>
</search>The search itself then happens on your server or website platform, and the visitor sees a normal results page. Nothing extra is downloaded on the pages where people simply read.
Search widgets: what loads before anyone types
Search widgets add features such as instant suggestions as you type, filters and spelling help. Those can be worth having. The question is when their code arrives. Google's guide to loading third-party JavaScript efficiently notes that a script from another origin may need to “perform a DNS lookup, establish a new HTTP connection”, and that synchronous scripts “delay DOM construction and rendering”.
So a widget installed with one line in the site header can quietly add work to every page view. For a carbon test this matters because GreenTracer measures one initial, uncached load of the page, without scrolling or clicking. Anything the widget loads at the start is counted; anything that waits for a visitor to use search is not. As an illustration, if a widget's files came to 300 kB, the Sustainable Web Design Model v4 would put that at about 0.044 g CO₂e per page view (about 0.036 g on a host listed as green). Your own figure depends on what your widget actually loads, which is why the measuring step below matters.
Load the search tool when someone uses it
You do not have to choose between a plain box and a rich search. A common pattern is to show the plain form on every page and fetch the heavier code only when a visitor clicks into the box or submits a search.
- Load code on demand. web.dev's guide to code splitting shows a form handler changed to use a dynamic import, so the code is fetched “only when the form is submitted by the user”. MDN describes
import()as a way to load a module “conditionally or on demand”. - Keep the form working without it. If the plain form submits to a results page, visitors can still search while the extra code is loading, or if it fails.
- Avoid blocking the page. Where a script must load at the start, the same web.dev guide advises loading third-party scripts asynchronously unless they have to run before the page can render.
- Ask the provider first. Before building anything, check the provider's own documentation for a lazy or on-demand option. This is the same idea as the click-to-load maps and chat in loading embeds only when wanted.
Built-in or add-on: questions to ask
If you are deciding how search should work, or reviewing what you already have, ask your web person:
- Does our platform offer its own search, and does it work as a form that leads to a results page?
- If we use a separate search service, which files does it load on a page where nobody searches?
- Is the search script loaded on every page, or only where search is shown?
- Can the instant suggestions load after the visitor clicks into the box?
- Is the add-on still needed? Plugins that were added years ago can linger; our guide to finding unused JavaScript shows how to spot them.
Measure before and after
- Open a typical page (not the search page) in Chrome with DevTools' Network panel open, tick “Disable cache” and reload. Our page weight guide walks through this.
- Use the Network panel's filters:
domain:shows only resources from a given domain, and “3rd-party requests” shows requests whose origin differs from the page. Note what the search provider loads before you type anything. - Make the change, reload, and confirm those files now appear only after you click into the search box.
- Try a real search on a phone and a desktop to check that results still appear.
- Check the page again and compare the new report with the old one; the report keeps earlier checks as history.
Sources
- MDN: <input type="search">
- MDN: the <search> element
- MDN: the <form> element (method and action)
- MDN: dynamic import()
- web.dev: efficiently load third-party JavaScript
- web.dev: reduce JavaScript payloads with code splitting
- Chrome for Developers: Network features reference
- Sustainable Web Design: estimating digital emissions (SWDM v4)



