# 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 %}
