Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Cssembed Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Pure php css embed

Frequently asked questions about Cssembed
How does ptachoire/cssembed reduce HTTP requests in Laravel applications?
The package scans your CSS files for `url(...)` references and replaces them with base64-encoded data URIs. This eliminates the need for separate HTTP requests to fetch images or fonts referenced in your stylesheets, directly embedding them into the CSS payload. It’s particularly useful for Laravel apps with static assets or external dependencies.
Can I use ptachoire/cssembed with Laravel Mix or Vite for build-time optimization?
Yes, but with caution. The package is designed for runtime or static embedding, so integrating it into Laravel Mix/Vite requires custom configuration. For build-time use, consider pre-processing CSS during deployment via a custom Artisan command or Laravel’s `booted` event, but ensure it doesn’t conflict with existing asset pipelines.
What Laravel versions does ptachoire/cssembed support?
The package is PHP-based and should work with Laravel 8.1+ due to its minimal dependencies. However, it lacks explicit Laravel-specific documentation, so test thoroughly in your environment. If you’re using Laravel 10+, ensure PHP 8.1+ compatibility, as the package itself doesn’t enforce version constraints.
How do I dynamically embed CSS in Blade templates using this package?
Create a custom Blade directive in your `AppServiceProvider`. For example, register `@cssEmbed` to process and output embedded CSS directly in your views. This approach works for runtime embedding but may impact performance if used on large or frequently changing stylesheets. Cache aggressively to mitigate overhead.
Are there performance trade-offs to embedding CSS as data URIs?
Yes. While embedding reduces HTTP requests, it increases the HTML payload size due to base64 encoding. Test with tools like Lighthouse or WebPageTest to measure the impact on metrics like Time to Interactive (TTI). For large assets, weigh the benefits against alternatives like lazy-loading or critical CSS strategies.
Does ptachoire/cssembed support caching for dynamic embedding?
The package itself doesn’t include built-in caching, but you can implement it using Laravel’s cache drivers (e.g., FileCache, Redis). Store embedded CSS outputs with a cache key tied to the original file’s hash or modification time. Clear the cache when CSS files change to ensure consistency.
What happens if a referenced CSS file or asset is missing during embedding?
The package will throw exceptions or return partial embeds if files are missing, depending on its error-handling logic. For production use, wrap embedding logic in try-catch blocks and provide fallbacks (e.g., load the original CSS file or a default stylesheet). Log errors to debug issues.
Is ptachoire/cssembed maintained, and are there alternatives for Laravel?
The package is unmaintained (last commit ~2019) and lacks Laravel-specific features. Alternatives include PostCSS plugins for data URI embedding, FilamentCSS for modern asset pipelines, or Laravel’s built-in `@stack` and `@vite` directives for asset bundling. Evaluate these based on your need for dynamic vs. static processing.
Can I use this package to embed user-uploaded CSS files safely?
No, embedding untrusted or user-provided CSS files poses significant security risks, including XSS or data exfiltration. The package is designed for trusted, static assets only. Validate all CSS inputs rigorously and avoid dynamic embedding for user-generated content.
How do I integrate ptachoire/cssembed into a Laravel service container for reuse?
Register the package as a singleton in your `AppServiceProvider` using the service container. For example, bind `CssEmbed` to a custom interface or alias for dependency injection. This allows you to reuse the embedder across middleware, Blade directives, or other services without reinstantiating it.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
yandex/translate-api
voku/simple_html_dom
league/flysystem-vfs
bkwld/upchuck
filament/spatie-laravel-tags-plugin
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php