Resolve #3499829 "Support inlining critical"
5 unresolved threads
Closes #3499829
Merge request reports
Activity
154 */ 155 protected function inlineCssFile(string $path): ?array { 156 $path = \strtok($path, "?"); 157 if (!\is_string($path)) { 158 return NULL; 159 } 160 $file_name = \sprintf('%s/%s', DRUPAL_ROOT, $path); 161 if (\file_exists($file_name)) { 162 $contents = \file_get_contents($path); 163 if (!\is_string($contents)) { 164 return NULL; 165 } 166 return [ 167 '#type' => 'html_tag', 168 '#tag' => 'style', 169 '#value' => Markup::create($contents), 147 * Turn a file into a renderable <style> tag. 148 * 149 * @param string $path 150 * File URL to turn into inline CSS. 151 * 152 * @return array|null 153 * Return NULL if the file does not exist. 154 */ 155 protected function inlineCssFile(string $path): ?array { 156 $path = \strtok($path, "?"); 157 if (!\is_string($path)) { 158 return NULL; 159 } 160 $file_name = \sprintf('%s/%s', DRUPAL_ROOT, $path); 161 if (\file_exists($file_name)) { 162 $contents = \file_get_contents($path); 2 2 version: VERSION 3 3 css: 4 4 base: 5 css/base/fonts.css: {} 6 css/base/variables.css: {} 7 css/base/base.css: {} 5 css/base/fonts.css: { attributes: { critical: true }, preprocess: false } I'd add a new top level item, the "critical" attribute is not a thing in the HTML spec.
not sure about using "inline", might be leaking too much implementation details
138 // @todo Defer all non critical CSS - 139 // https://www.drupal.org/project/drupal/issues/2989324 140 $elements[] = $asset; 141 } 142 143 return \array_filter($elements); 144 } 145 146 /** 147 * Turn a file into a renderable <style> tag. 148 * 149 * @param string $path 150 * File URL to turn into inline CSS. 151 * 152 * @return array|null 153 * Return NULL if the file does not exist. 154 */ 155 protected function inlineCssFile(string $path): ?array { 156 $path = \strtok($path, "?"); 157 if (!\is_string($path)) { 158 return NULL; 159 } 160 $file_name = \sprintf('%s/%s', DRUPAL_ROOT, $path); 161 if (\file_exists($file_name)) { 162 $contents = \file_get_contents($path); 163 if (!\is_string($contents)) { 164 return NULL; 165 } 166 return [ 167 '#type' => 'html_tag', 168 '#tag' => 'style', 169 '#value' => Markup::create($contents),
Please register or sign in to reply