Laravel-caffeine prevents form sessions from expiring due to inactivity. It works by sending a lightweight AJAX request at regular intervals when a form with a _token or csrf-token is present on the page. This ensures the session remains active even when a user leaves the form open for extended periods. It addresses the issue of default session timeouts interfering with user workflows.
The package offers flexible control over how the session is kept alive, allowing for configuration of the drip interval, a custom route for the AJAX request, and the ability to disable it for specific pages via meta tags or middleware. It's designed to avoid exposing the CSRF token on unsecured endpoints and respects CSRF validation. It's also an efficient solution, designed for Laravel 11, 12, and 13.
- Automatic Activation: Automatically detects and caffeinates forms based on the presence of
_tokenorcsrf-token. - Configuration Options: Provides configurable drip interval, route, and disable mechanisms for fine-grained control.
- Middleware Support: Offers both global and route-specific middleware for enabling and disabling caffeine.
- CSRF Protection: Preserves CSRF token validation during the keep-alive process, preventing security vulnerabilities.
- Flexible Usage: Supports integration with traditional Blade forms and can be selectively disabled for specific pages or routes.
The project is actively maintained with recent commits and a clear release history. It addresses reported issues and follows coding standards. Comprehensive documentation is available, alongside active community engagement. The package is relatively stable and suitable for production environments.
Laravel-caffeine is ideal for developers building Laravel applications where users frequently engage with long forms. It enhances user experience by preventing session timeouts. It provides a simple and effective solution for managing session lifetimes without compromising security or requiring complex setup. Itβs beneficial for any application handling lengthy forms or processes requiring extended user sessions.
