diff --git a/src/CriticalCssServiceProvider.php b/src/CriticalCssServiceProvider.php index 193d47c..b9d3ae7 100644 --- a/src/CriticalCssServiceProvider.php +++ b/src/CriticalCssServiceProvider.php @@ -105,7 +105,8 @@ protected function registerAppBindings() $generator->setOptions( $app['config']->get('criticalcss.width'), $app['config']->get('criticalcss.height'), - $app['config']->get('criticalcss.ignore') + $app['config']->get('criticalcss.ignore'), + $app['config']->get('criticalcss.timeout', 30000) ); return $generator; diff --git a/src/CssGenerators/CriticalGenerator.php b/src/CssGenerators/CriticalGenerator.php index be200bb..4d74a1d 100644 --- a/src/CssGenerators/CriticalGenerator.php +++ b/src/CssGenerators/CriticalGenerator.php @@ -34,6 +34,9 @@ class CriticalGenerator implements CssGeneratorInterface /** @var array */ protected $ignore; + /** @var int|null */ + protected $timeout; + /** * {@inheritdoc} */ @@ -61,17 +64,19 @@ public function setCriticalBin($critical) /** * Set optional options for Critical. * - * @param int $width - * @param int $height - * @param array $ignore + * @param int $width + * @param int $height + * @param array $ignore + * @param int|null $timeout * * @return void */ - public function setOptions($width = 900, $height = 1300, array $ignore = []) + public function setOptions($width = 900, $height = 1300, array $ignore = [], $timeout = null) { $this->width = $width; $this->height = $height; $this->ignore = $ignore; + $this->timeout = $timeout; } /** @@ -92,6 +97,10 @@ public function generate($uri, $alias = null) '--minify', ]); + if (!is_null($this->timeout)) { + $builder->add('--timeout='.$this->timeout); + } + foreach ($this->css as $css) { $builder->add('--css='.$css); } diff --git a/src/HtmlFetchers/LaravelHtmlFetcher.php b/src/HtmlFetchers/LaravelHtmlFetcher.php index e25f4ca..8932999 100644 --- a/src/HtmlFetchers/LaravelHtmlFetcher.php +++ b/src/HtmlFetchers/LaravelHtmlFetcher.php @@ -16,9 +16,6 @@ class LaravelHtmlFetcher implements HtmlFetcherInterface /** @var \Illuminate\Contracts\Foundation\Application */ protected $app = null; - /** @var \Closure */ - protected $appMaker; - /** * Create a new instance. * diff --git a/src/config/criticalcss.php b/src/config/criticalcss.php index 8e51ac3..db5adba 100644 --- a/src/config/criticalcss.php +++ b/src/config/criticalcss.php @@ -8,7 +8,7 @@ */ return [ - + /* |-------------------------------------------------------------------------- | Routes @@ -29,7 +29,7 @@ | parameters filled out.) Make sure the request won't 404. | */ - + 'routes' => [ // 'static/route', // In Blade: `@criticalCss('static/route')` // 'users/profile' => 'users/1', // In Blade: `@criticalCss('users/profile')` @@ -45,7 +45,7 @@ | The file is relative to the public path, i.e., `public_path($css)`. | */ - + 'css' => ['css/app.css', 'css/app2.css'], /* @@ -56,7 +56,7 @@ | Width and height of the target viewport. | */ - + 'width' => 1300, 'height' => 900, @@ -70,7 +70,7 @@ | @see https://github.com/bezoerb/filter-css | */ - + 'ignore' => [ // Removes @font-face blocks // '@font-face', @@ -90,7 +90,7 @@ | The directory which the generated critical-path CSS is stored. | */ - + 'storage' => 'critical-css', /* @@ -105,7 +105,7 @@ | Remember to run `php artisan view:clear` after re-disabling this. | */ - + 'pretend' => env('CRITICALCSS_PRETEND', false), /* @@ -118,7 +118,7 @@ | If your app is running on Laravel 5.0, this must be disabled. | */ - + 'blade_directive' => true, /* @@ -131,7 +131,20 @@ | installed globally, you may simply use 'critical'. | */ - + 'critical_bin' => base_path('node_modules/.bin/critical'), + /* + |-------------------------------------------------------------------------- + | Timeout + |-------------------------------------------------------------------------- + | + | Sets a maximum timeout, in milliseconds, for the CSS generation of a route. + | This parameter is passed to the Critical executable. + | Default value is 30000. + | + */ + + 'timeout' => 30000, + ]; diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 629b45c..11d5604 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -12,6 +12,7 @@ class ConfigTest extends TestCase 'pretend' => 'string', 'blade_directive' => 'bool', 'critical_bin' => 'string', + 'timeout' => 'integer', ]; public function testConfigIsOk()