[{"data":1,"prerenderedAt":36},["ShallowReactive",2],{"blog:post:en:cut-scraping-bandwidth-with-etags":3,"blog:related:en:cut-scraping-bandwidth-with-etags":23},{"slug":4,"lang":5,"title":6,"summary":7,"date":8,"tags":9,"tag_slugs":15,"thumbnail_url":16,"translations":17,"body":18,"asset_base":19,"checksum":20,"published_at":21,"content_updated_at":22},"cut-scraping-bandwidth-with-etags","en","Save Scraping Bandwidth with ETags and 304 Responses","Turn repeat scrapes into cheap 304 Not Modified responses with ETags and If-Modified-Since, cutting bandwidth and origin load.","2026-11-18",[10,11,12,13,14],"web-scraping","http","performance","python","proxy-configuration",[10,11,12,13,14],"https://blog-api.ro-proxy.com/api/blog/posts/cut-scraping-bandwidth-with-etags/thumbnail.svg?lang=en",[5],"Every time a scraper re-fetches a page that hasn't changed, you pay for it three times: bandwidth on your own connection, bandwidth metered through your proxy, and load on the origin server. For feeds you poll on a schedule — price lists, sitemaps, JSON APIs, changelogs — most of those fetches return bytes you already have. Conditional HTTP requests fix that. Instead of downloading the whole body again, you ask the server \"has this changed since I last looked?\" and it answers with a tiny `304 Not Modified` and no body at all.\n\nThis post shows how to add conditional requests to a scraper, why they work well with rotating proxies, and the edge cases that trip people up.\n\n## How conditional requests work\n\nTwo validators let a server describe a specific version of a resource:\n\n- `ETag` — an opaque token like `\"a1b2c3\"` that changes whenever the content changes.\n- `Last-Modified` — an HTTP-date of the last change.\n\nOn your first request the server returns the body plus one or both validators. On later requests you send them back as request headers:\n\n- `If-None-Match` carries the stored `ETag`.\n- `If-Modified-Since` carries the stored `Last-Modified`.\n\nIf the resource is unchanged, the server replies `304 Not Modified` with headers only. If it changed, you get a normal `200 OK` with the new body and fresh validators. Either way you always hold a correct copy: the one you stored, or the new one.\n\nThe bandwidth math is the whole point. A 50 KB JSON feed polled every five minutes is roughly 14 MB/hour if you always download it. With validators, each unchanged poll costs a few hundred bytes.\n\n## Why this pairs well with rotating proxies\n\nWhen you fetch through a rotating proxy, each request may leave from a different IP. That rules out any cache tied to a single connection or IP — but conditional requests rely on neither. The validators and the last known body live on your side, keyed by URL. The server doesn't care which IP asked; it only compares the validator you send against its current version. So you keep the savings on every poll no matter which exit IP the proxy hands you.\n\nConfigure the proxy once and reuse it for every request:\n\n```python\nimport requests\n\nPROXIES = {\n    \"http\": \"http://USERNAME:PASSWORD@GATEWAY_HOST:HTTP_PORT\",\n    \"https\": \"http://USERNAME:PASSWORD@GATEWAY_HOST:HTTP_PORT\",\n}\n```\n\nIf you fetch through a rotating proxy such as RoProxy, that gateway URL is all you need — the conditional-request logic below behaves identically regardless of which IP a request exits from.\n\n## A reusable conditional fetcher\n\nKeep a small cache mapping each URL to its stored validators and body. A plain dict works for a single run; swap in SQLite or Redis when you want it to survive restarts.\n\n```python\ndef fetch(url, cache):\n    headers = {}\n    entry = cache.get(url)\n    if entry:\n        if entry.get(\"etag\"):\n            headers[\"If-None-Match\"] = entry[\"etag\"]\n        if entry.get(\"last_modified\"):\n            headers[\"If-Modified-Since\"] = entry[\"last_modified\"]\n\n    resp = requests.get(url, headers=headers, proxies=PROXIES, timeout=30)\n\n    if resp.status_code == 304:\n        return cache[url][\"body\"], True          # unchanged, reuse stored body\n\n    resp.raise_for_status()\n    if resp.status_code == 200:\n        cache[url] = {\n            \"etag\": resp.headers.get(\"ETag\"),\n            \"last_modified\": resp.headers.get(\"Last-Modified\"),\n            \"body\": resp.text,\n        }\n        return resp.text, False                   # fresh content\n```\n\nThe second return value tells your pipeline whether the content changed, so you can skip downstream parsing when it didn't. That is often a bigger win than the bandwidth itself: no need to re-parse, re-diff, or re-store identical data.\n\n### Keep request headers stable\n\nAn `ETag` is only valid for the exact request that produced it. If your first fetch sends `Accept-Encoding: gzip` and a later one doesn't, or you rotate `User-Agent` values between calls, the server may treat them as different representations and ignore your validator. Pick one set of headers per URL and reuse it so the validators keep matching.\n\n## Verifying it with cURL\n\nYou can confirm a server supports conditional requests before writing any code. First fetch and capture the validators:\n\n```bash\ncurl -s -D headers.txt \\\n  -x http://USERNAME:PASSWORD@GATEWAY_HOST:HTTP_PORT \\\n  https://example.com/data.json -o body.json\ngrep -i '^etag:' headers.txt\n```\n\nThen replay the validator and check the status code:\n\n```bash\nETAG=$(grep -i '^etag:' headers.txt | tr -d '\\r' | awk '{print $2}')\ncurl -s -o /dev/null -w \"%{http_code}\\n\" \\\n  -H \"If-None-Match: $ETAG\" \\\n  -x http://USERNAME:PASSWORD@GATEWAY_HOST:HTTP_PORT \\\n  https://example.com/data.json\n```\n\nA `304` in the output means conditional requests work. To confirm which IP the request exited from, ask an echo service through the same proxy:\n\n```bash\ncurl -s -x http://USERNAME:PASSWORD@GATEWAY_HOST:HTTP_PORT \\\n  https://api.ipify.org?format=json\n```\n\n## Edge cases that bite\n\n- Servers that ignore validators. Some origins, and some intermediaries, always return `200` with a full body. Log how often you actually get `304`; if it is never, the savings will not materialize and you should lean on your own change detection instead.\n- Weak ETags. A value like `W/\"a1b2c3\"` is a weak validator — semantically equivalent content, byte-level differences ignored. Echo it back verbatim in `If-None-Match`; do not strip the `W/`.\n- `Vary` headers. If the response says `Vary: Accept-Language`, the ETag is per-language. Keep the relevant request headers constant, or key your cache by URL plus the varying header, so you never serve the wrong version.\n- Only cache safe requests. Conditional requests are meaningful for `GET` and `HEAD`. Do not attach stored validators to `POST` or other state-changing calls.\n- Etiquette still applies. A `304` reduces load, but keep honoring `robots.txt`, your rate limits, and the site's terms. Cheaper polling is not a license to poll aggressively.\n\n## Measuring the payoff\n\nLog two counters per URL: total requests and `304` responses. Their ratio is your hit rate. A well-behaved feed you poll every few minutes should sit well above 50% once the first fetch has primed the cache. Track bytes downloaded before and after — you and your proxy provider both benefit when most polls shrink to a few hundred bytes. If a URL's hit rate stays near zero, the server is not honoring validators; move it to explicit change detection rather than keep paying for full downloads.\n\n## Where to store the cache\n\nFor a one-off script, an in-memory dict is fine. For scheduled jobs that run in separate processes, persist the cache so you don't lose validators between runs:\n\n- SQLite: one row per URL with `etag`, `last_modified`, and a content hash.\n- Redis: `SET url:\u003Chash> \u003Cjson>` with no expiry, so validators live as long as the data does.\n\nStore a hash of the body alongside it. If a `200` returns a body whose hash matches the old one, treat it as unchanged even when the server skipped the `304` — a cheap safety net against wasteful reprocessing.\n\n## Conclusion\n\nConditional requests are one of the least glamorous and most effective optimizations in a scraper's toolkit. Send the validators you already have, let the server answer `304` when nothing changed, and you cut bandwidth, proxy traffic, and origin load in one move. Wire the fetcher above into your poller, keep routing fetches through RoProxy, and log your `304` rate to confirm the payoff — unchanged pages will cost you almost nothing.\n","https://blog-api.ro-proxy.com/api/blog/posts/cut-scraping-bandwidth-with-etags/assets","55735530427e8e487f484ed5989af27039332f9da452fbe9ddd23d944360d69b","2026-11-18T01:03:27.901133Z","2026-11-18T01:03:27.904446Z",[24,28,32],{"slug":25,"title":26,"summary":27},"optimizing-proxy-connection-pooling-high-throughput-python","Optimizing Proxy Connection Pooling for High-Throughput Python Scrapers","Learn how to implement connection pooling, session reuse, and keep-alive optimization to dramatically reduce latency and improve throughput in Python web scraping projects.",{"slug":29,"title":30,"summary":31},"tunneling-https-through-http-proxy-python","Tunneling HTTPS Through an HTTP Proxy in Python","Learn how to tunnel HTTPS traffic through an HTTP proxy using only Python's standard library, with basic auth and exit IP verification.",{"slug":33,"title":34,"summary":35},"adaptive-proxy-rotation-adjusting-proxies-based-on-response-codes-and-latency","Adaptive Proxy Rotation: Adjusting Proxies Based on Response Codes and Latency","Learn how to monitor request outcomes and adjust your proxy pool dynamically to improve success rates and reduce bans.",1796251609633]