PHPackages                             inventor96/inertia-offline-mako - 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. [Framework](/categories/framework)
4. /
5. inventor96/inertia-offline-mako

ActiveLibrary[Framework](/categories/framework)

inventor96/inertia-offline-mako
===============================

Mako framework adapter for inventor96/inertia-offline.

v0.2.1(2mo ago)010↓92.3%MITPHPPHP &gt;=8.1

Since Apr 3Pushed 2mo agoCompare

[ Source](https://github.com/inventor96/inertia-offline-mako)[ Packagist](https://packagist.org/packages/inventor96/inertia-offline-mako)[ RSS](/packages/inventor96-inertia-offline-mako/feed)WikiDiscussions main Synced today

READMEChangelog (4)Dependencies (6)Versions (5)Used By (0)

Inertia Offline for Mako
========================

[](#inertia-offline-for-mako)

A Mako framework adapter for [inertia-offline](https://github.com/inventor96/inertia-offline), enabling offline-first capabilities for Inertia.js applications.

> Beta: offline read-only layer for Inertia.js apps, focused on safe cached content and navigation fallback.

This PHP backend package is designed to work with [`inertia-offline`](https://github.com/inventor96/inertia-offline-js) (the JS/TS frontend service worker library). Both the frontend and the backend aspects are required for an Inertia.js app.

Installation
------------

[](#installation)

### 1. Install via Composer

[](#1-install-via-composer)

```
composer require inventor96/inertia-offline-mako
```

### 2. Register the Package in Mako

[](#2-register-the-package-in-mako)

Add the package to your `app/config/application.php`:

```
'packages' => [
    'web' => [
        inventor96\InertiaOfflineMako\InertiaOfflinePackage::class,
    ],
],
```

Usage
-----

[](#usage)

See [inertia-offline](https://github.com/inventor96/inertia-offline-php?tab=readme-ov-file#1-offlinecacheable-attribute) for usage instructions on how to mark routes as offline-cacheable and configure the client-side service worker.

Configuration
-------------

[](#configuration)

The default configuration for the package works out of the box, but you can create an override file at `app/config/packages/inertia-offline/offline.php` to customize settings:

```
return [
	/**
	 * The class that implements `PaginationUrlExpanderInterface` to use for
	 * expanding pagination URLs in the `OfflineRoutes` adapter. When left null
	 * or empty, the default is to use an adapter that relies on the built-in
	 * pagination of Mako.
	 */
	'pagination_expander' => null,

	/**
	 * The time (in seconds) that the offline route list response should be
	 * cached by clients and intermediate caches. Default is 86400 (24 hours).
	 */
	'route_list_cache_ttl' => 86400,

	/**
	 * The path for the route that serves the list of offline routes. Must be
	 * the same as `routeMetaPath` in the client config. Set to null or empty
	 * to disable automatic registration of the route (e.g. you want to
	 * register it manually). Default is `/pwa/offline-routes`.
	 */
	'routes_path' => '/pwa/offline-routes',

	/**
	 * The path for the route that serves the Inertia version. Must be the same
	 * as `routeVersionPath` in the client config. Set to null or empty to
	 * disable automatic registration of the route (e.g. you want to register
	 * it manually). Default is `/pwa/offline-version`.
	 */
	'version_path' => '/pwa/offline-version',
];
```

Etag Middleware
---------------

[](#etag-middleware)

In case you don't have Etag support in your application, you can use the `ConditionalEtag` middleware provided by the package. This middleware generates ETags for responses related to offline functionality. Enabling ETag support is optional, but is highly recommended for better caching and performance for the client-side service worker.

### Register Globally

[](#register-globally)

As the middleware automatically avoids adding ETags to non-offline responses, you can safely register it globally. Add the middleware to your `app/http/routing/middleware.php` in the global middleware list, setting a high priority to ensure it runs last:

```
$dispatcher
    ->registerGlobalMiddleware(\inventor96\InertiaOfflineMako\ConditionalEtag::class)
    ->setMiddlewarePriority(\inventor96\InertiaOfflineMako\ConditionalEtag::class, 1000);
```

Custom Pagination URL Expander
------------------------------

[](#custom-pagination-url-expander)

By default, the package uses Mako's built-in pagination. If your application uses custom pagination patterns, implement a custom expander.

### Example Implementation

[](#example-implementation)

Create a class that implements `PaginationUrlExpanderInterface`:

```
