# Optimizing Traffic

Your automation scripts often download unnecessary resources such as images, stylesheets, fonts, and other media files. These files consume bandwidth and can slow down your scraping operations.

You can block these unnecessary resources from loading entirely. By intercepting network requests and selectively blocking media files, you can focus only on the data you actually need.

These code snippets works with both Playwright and Puppeteer to block media resources before they're downloaded:

{% tabs %}
{% tab title="Python" %}

```python
async def block_resources(route):
    request = route.request
    resource_type = request.resource_type
    if resource_type in ['image', 'stylesheet', 'media', 'font']:
        await route.abort()
    else:
        await route.continue_()
await page.route('**/*', block_resources)
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
await page.route('**/*', (route) => {
    const request = route.request();
    const type = request.resourceType();

    if (['image', 'stylesheet', 'media', 'font'].includes(type)) {
        return route.abort();
    }

    return route.continue();
});
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developers.oxylabs.io/scraping-solutions/headless-browser/optimizing-traffic.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
