campaigningbureau/critical-laravel-routes
| Install | |
|---|---|
composer require campaigningbureau/critical-laravel-routes |
|
| Latest Version: | v1.3.0 |
| PHP: | ^8.1 |
| License: | MIT |
| Last Updated: | Oct 23, 2024 |
| Links: | GitHub · Packagist |
Critical Laravel Routes
Automatically create and link Critical CSS for static routes.
Supports Laravel 7.*
Installation
Just require the package via composer:
composer require campaigningbureau/critical-laravel-routes
The package gets automatically discovered by Laravel.
Usage
-
All static routes, that should use critical css, need to be named and have a
criticalattribute set totrue:Route::get('/', ['as' => 'index', 'uses' => 'ViewController@index', 'critical' => true]); -
Generate the JSON that contains all critical routes:
php artisan critical-urls:generate -
The generated file needs to be required in the webpack.mix.js and set as
urlswhen creating the critical css:// urls that need to be passed for critical css const criticalUrls = require('./critical-routes.json'); ... mix.criticalCss({ enabled: mix.inProduction(), paths: { base: 'http://your-website.com', templates: 'public/css/' }, urls: criticalUrls, options: { minify: true, }, });When generating the css, one css file per defined route is created and saved.
-
Automatically import the content of the critical css file (if it exists for the route) in the blade template as inline styles:
{!! \CriticalLaravelRoutes::inlineCriticalCss() !!}Alternatively, the critical css file can be linked with:
{!! \CriticalLaravelRoutes::linkCriticalCss() !!}This can be used safely vor every existing route, so it is best to put it in the base layout. If no critical css file is found for a route, nothing is displayed.
Configuration
The config can be changed by publishing the configuration file:
$ php artisan vendor:publish --provider="CampaigningBureau\CriticalLaravelRoutes\CriticalLaravelRoutesServiceProvider"
It is possible to configure the name of the generated JSON file and the suffix for the critical css filess.
Related Packages
Powerful PHP database abstraction layer (DBAL) with many features for database s...
Laravel Serializable Closure provides an easy and secure way to serialize closur...
Cli error handling for console/command-line PHP applications.
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| v1.3.0 | ^8.1 | ^10.0| | MIT | |
| v1.2.0 | ^7.2| | ^7.0| | MIT | |
| v1.1.0 | ^7.2 | ^7.0 | MIT | |
| v1.0.1 | ^7.2 | ^7.0 | MIT | |
| v1.0 | ^7.2 | ^7.0 | MIT |