public function getHtmlCss($cssfiles) { $files = is_array($cssfiles) ? $cssfiles : func_get_args(); $cacheKey = CssKeys::getSingleKey(Request::path()); if (Cache::has($cacheKey)) { $cssoutput = Cache::get($cacheKey); return $this->getAsyncStylesheet($cssoutput, $files); } else { return $this->getStylesheetLink($files); } }
public function testGenerateAsyncCSS() { $html = file_get_contents(__DIR__ . '/resources/index.html'); $urlPath = '/example'; // create $job = new BuildAsyncCSS($html, $urlPath); $job->handle(); // check $cssOutput = Cache::get(CssKeys::getSingleKey($urlPath)); $this->assertFalse(empty($cssOutput), 'Css output is empty'); $start = '@charset "UTF-8"'; $this->assertStringStartsWith($start, $cssOutput, 'Css output maybe wrong'); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if ($request->getMethod() !== 'GET') { return $next($request); } $response = $next($request); if ($this->isHtmlResponse($response)) { $urlPath = $request->getRequestUri(); // var_dump('arsch'.$urlPath); $cacheKey = CssKeys::getSingleKey($urlPath); //// var_dump($cacheKey); //// dd(Cache::has($cacheKey)); if (Cache::has($cacheKey) === false) { // start a asynccss job in queues mode $html = $response->getContent(); $this->dispatch(new BuildAsyncCSS($html, $urlPath)); } } return $response; }
/** * Create a new job instance. * * @return void */ public function __construct($html, $urlPath) { $this->cacheKey = CssKeys::getSingleKey($urlPath); $this->servicePath = base_path('node_modules/critical/cli.js'); $this->html = $html; }