PHPackages                             vacatia/varnish-mobiletranslate - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. vacatia/varnish-mobiletranslate

AbandonedArchivedLibrary[Caching](/categories/caching)

vacatia/varnish-mobiletranslate
===============================

03.4kPHP

Since Feb 19Pushed 7y ago17 watchersCompare

[ Source](https://github.com/vacatia/varnish-mobiletranslate)[ Packagist](https://packagist.org/packages/vacatia/varnish-mobiletranslate)[ RSS](/packages/vacatia-varnish-mobiletranslate/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

Varnish Mobile Detect
=====================

[](#varnish-mobile-detect)

\###Goal: Drop-in varnish solution to mobile user detection based on the  library.

\###How: A VCL script that adds a `X-UA-Device` header to the request.

Device TypeX-UA-DevicePhonephoneTablettabletOtherdesktop\###Requirements Varnish 3 is a requirement. If you venture running this with Varnish 2, there is no gurantee for support. It is also helpful to know understand the basics of the VCL language and workflow. This is not a VMOD module, so no compiling is required.

\###Installation

1. Download the mobile\_detect.vcl file into your vcl config directory. `/etc/varnish/`

- `wget https://raw2.github.com/willemk/varnish-mobiletranslate/master/mobile_detect.vcl`

2. Include the `mobile_detect.vcl` in your `default.vcl` file (See examples below)
3. Call `devicedetect` from vcl\_recv in varnish (See examples below)

\###Usage ####Sample use case: Different back ends Using a different backend for mobile than for desktop

```
include "mobile_detect.vcl";

backend mobile {
    .host = "10.0.0.1";
    .port = "80";
}

sub vcl_recv {

    call devicedetect;

    if (req.http.X-UA-Device ~ "^mobile") {
        set req.backend = mobile;
    }
}

```

\####Sample use case: Normalize the user-agent string for the backend The backend receives the simplified user-agent generated by the mobile\_detect. The backend can then serve different content accordingly. It will then cache it by device type.

```
include "mobile_detect.vcl";

sub vcl_recv {

    call devicedetect;

    if (req.http.X-UA-Device) {
        set req.http.User-Agent = req.http.X-UA-Device;
        unset req.http.X-UA-Device;
    }
}

sub vcl_hash {
    #Default Hash
    hash_data(req.url);
    if (req.http.host) {
        hash_data(req.http.host);
    } else {
        hash_data(server.ip);
    }

    #Also hash based on device type
    if (req.http.X-UA-Device) {
        hash_data(req.http.X-UA-Device);
    }

    return (hash);
}

```

\####Sample use case: Cache based on device type If your backend generates the different content for the same URL based on device type, it should be cached accoding to that device type.

```
include "mobile_detect.vcl";

sub vcl_recv {

    call devicedetect;

}

sub vcl_hash {
    #Default Hash
    hash_data(req.url);
    if (req.http.host) {
        hash_data(req.http.host);
    } else {
        hash_data(server.ip);
    }

    #Also hash based on device type
    if (req.http.X-UA-Device) {
        hash_data(req.http.X-UA-Device);
    }

    return (hash);
}

```

\###Bugs &amp; Features

If you have any bug reports, feature request or want to submit a pull request, please use the appropriate github tools.

\###Thanks

Thanks to these projects for help and inspiration

\###Update mobile\_detect.vcl

You can update the mobile detection rules using latest from `serbanghita/Mobile-Detect`, by executing `php varnishtranslate.php`. Then push the `mobile_detect.vcl` to the repo.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 86.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/647137?v=4)[Radu Topala](/maintainers/radutopala)[@radutopala](https://github.com/radutopala)

---

Top Contributors

[![willemk](https://avatars.githubusercontent.com/u/925449?v=4)](https://github.com/willemk "willemk (31 commits)")[![dbpolito](https://avatars.githubusercontent.com/u/347400?v=4)](https://github.com/dbpolito "dbpolito (2 commits)")[![radutopala](https://avatars.githubusercontent.com/u/647137?v=4)](https://github.com/radutopala "radutopala (2 commits)")[![carlbastos](https://avatars.githubusercontent.com/u/12959159?v=4)](https://github.com/carlbastos "carlbastos (1 commits)")

### Embed Badge

![Health badge](/badges/vacatia-varnish-mobiletranslate/health.svg)

```
[![Health](https://phpackages.com/badges/vacatia-varnish-mobiletranslate/health.svg)](https://phpackages.com/packages/vacatia-varnish-mobiletranslate)
```

###  Alternatives

[react/cache

Async, Promise-based cache interface for ReactPHP

444112.4M40](/packages/react-cache)[wp-media/wp-rocket

Performance optimization plugin for WordPress

7431.3M3](/packages/wp-media-wp-rocket)[illuminate/cache

The Illuminate Cache package.

12835.6M1.4k](/packages/illuminate-cache)[colinmollenhour/php-redis-session-abstract

A Redis-based session handler with optimistic locking

6325.6M14](/packages/colinmollenhour-php-redis-session-abstract)[cheprasov/php-redis-client

Php client for Redis. It is a fast, fully-functional and user-friendly client for Redis, optimized for performance. RedisClient supports the latest versions of Redis starting from 2.6 to 6.0

1281.2M21](/packages/cheprasov-php-redis-client)[amphp/redis

Efficient asynchronous communication with Redis servers, enabling scalable and responsive data storage and retrieval.

165634.7k44](/packages/amphp-redis)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
