ptachoire/cssembed
Embed and inline images in CSS by converting them to data URIs. ptachoire/cssembed scans your stylesheets for url(...) references and replaces eligible assets with base64-encoded content, reducing HTTP requests and simplifying distribution of self-contained CSS.
ptachoire/cssembed) enables embedding external CSS files directly into HTML, reducing HTTP requests and improving page load performance. This aligns well with performance-critical applications (e.g., SPAs, marketing sites, or legacy systems with many external CSS dependencies).FileCache or Redis).booted event or a custom Artisan command) avoids runtime overhead but may complicate CI/CD pipelines.@stack + asset bundling)?@cssEmbed) to simplify usage. Example:
// In AppServiceProvider::boot()
Blade::directive('cssEmbed', function ($expression) {
return "<?php echo \\Ptachoire\\CssEmbed\\CssEmbed::embed(" . $expression . "); ?>";
});
Usage: @cssEmbed('css/styles.css')$this->app->singleton('cssEmbed', function () {
return new \Ptachoire\CssEmbed\CssEmbed();
});
booted event to pre-process CSS during deployment:
use Ptachoire\CssEmbed\CssEmbed;
public function booted()
{
$cssEmbed = new CssEmbed();
$embeddedCss = $cssEmbed->embed(public_path('css/styles.css'));
file_put_contents(public_path('css/embedded.css'), $embeddedCss);
}
public function handle($request, Closure $next)
{
$response = $next($request);
$response->setContent(
str_replace(
'<link rel="stylesheet" href="css/styles.css">',
CssEmbed::embed('css/styles.css'),
$response->getContent()
)
);
return $response;
}
ExtractTextPlugin or Vite).config/cssembed.php to whitelist/blacklist files.@import, variables, media queries).cache/).booted event.CssEmbed class (mock HTTP requests).if ($embeddedCss === false) {
Log::warning("CSS embed failed for file: {$filePath}", ['error' => $exception]);
}
<link> tags via config).How can I help you explore Laravel packages today?