PHP code example of develupers / laravel-cdn-headers
1. Go to this page and download the library: Download develupers/laravel-cdn-headers library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
develupers / laravel-cdn-headers example snippets
'routes' => [
'home' => 300, // 5 minutes
'products.*' => 3600, // 1 hour for all product routes
'api.*' => 600, // 10 minutes for all API routes
],
return [
// Enable/disable the middleware
'enabled' => env('CDN_HEADERS_ENABLED', true),
// Auto-register as global middleware or manual registration
'middleware_registration' => env('CDN_HEADERS_REGISTRATION', 'global'),
// Skip authenticated users
'skip_authenticated' => true,
// Remove cookies from cacheable responses
'remove_cookies' => true,
// Define cacheable routes and their TTL in seconds
'routes' => [
'home' => 300, // 5 minutes
'products.index' => 3600, // 1 hour
'products.show' => 7200, // 2 hours
'products.*' => 3600, // All product routes
'api.v1.*' => 600, // All API v1 routes
],
// URL patterns (for routes without names)
'patterns' => [
'/blog/*' => 1800,
'/api/v2/*' => 600,
],
// Exclude specific routes
'excluded_routes' => [
'admin.*',
'dashboard.*',
],
// Security settings
'remove_csrf_tokens' => true, // Remove CSRF tokens from cached pages
];
// As global middleware (runs on all routes)
protected $middleware = [
// ... other middleware
\Develupers\CdnHeaders\Http\Middleware\CdnHeadersMiddleware::class,
];
// In your login controller
Cookie::queue('authenticated', '1', 60 * 24 * 30);
// In your logout controller
Cookie::queue(Cookie::forget('authenticated'));
'inject_csrf_loader' => true, // Enable auto-injection
'csrf_loader_routes' => [
'auto' => true, // Inject on any page where CSRF was removed
// Or specify exact routes (when auto is false)
'routes' => [
'contact.show',
'auth.login',
'auth.register',
],
],
'csrf_endpoint' => '/users/csrf-token', // Your CSRF endpoint
Route::get('/users/csrf-token', function () {
return response()->json(['csrf_token' => csrf_token()]);
});