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

Css Tidy Laravel Package

cerdic/css-tidy

CSSTidy is a PHP CSS parser and minifier with full CSS3 support. Optimizes and fixes styles without regex for higher reliability. Includes web UI, core parser class, and a standalone CLI (pcsstidy).

View on GitHub
Deep Wiki
Context7

Getting Started

Install via Composer: composer require cerdic/css-tidy. Begin with the minimal workflow: instantiate csstidy, parse a CSS string, and output minified content. Ideal for first use in a Laravel context—e.g., minifying inline <style> blocks in Blade templates or pre-minifying CSS from a CMS before storage. Start by reviewing class.csstidy.php for core API methods (parse(), get_cfg(), print_errors()) and css_optimiser.php (if present) for CLI/web UI patterns. A minimal Laravel service provider or closure example:

$csstidy = new \csstidy();
$csstidy->set_cfg('optimise_shorthands', 1);
$csstidy->parse($unminified_css);
return $csstidy->print->compressed();

Implementation Patterns

  • Build-time optimization: Create an Artisan command (php artisan css:minify) that scans public/build/css/*.css, minifies using this package, and overwrites outputs—especially useful when integrating with legacy systems or non-Node asset pipelines.
  • Middleware-based runtime minification: In App\Http\Middleware\MinifyInlineStyles, wrap CSS extracted from @style Blade directives (e.g., from rich-text editors) in a request lifecycle hook. Cache the result using Laravel’s cache (e.g., Cache::rememberForever("css-{$hash}", fn() => $minified)) to avoid repeated parsing.
  • Post-bundler enrichment: Add a post-vite step that runs after Vite builds to apply additional optimizations (e.g., optimise_shorthands=2, remove_duplicate_rules=true) Laravel Mix/Vite skips—e.g., preserving !important comments via set_cfg('preserve_critical_comments', true).
  • Bulk processing CLI: Use bin/pcsstidy to pre-minify vendor CSS (e.g., old admin themes) during CI or before deployment, reducing disk I/O vs. runtime parsing.

Gotchas and Tips

  • Performance trap: Parsing is robust (no regex) but slow. Never use in hot paths (e.g., per-request minification without caching). Profile with microtime(true); if >5ms per request, cache aggressively.
  • Option gotchas: template presets override explicit settings—always test set_cfg('template', 'high') vs. set_cfg('optimise_shorthands', 2) in isolation. Some legacy options (reverse_left_and_right) are ignored in v2+; use get_cfg() to verify active config.
  • Error handling: Uncaught parse errors crash—wrap calls in try/catch or use $csstidy->print_errors() before output to surface CSS syntax issues (e.g., unclosed brackets) gracefully.
  • Extensibility limits: The class is not PSR-compliant and uses global state. Wrap in a CssMinifierService with DI (->bind(CssMinifierInterface::class, fn() => new CssMinifierService())) to enable testability and Laravel caching.
  • PHP 8+ caveats: Despite v2.0.0 claiming PHP 7.1+ compatibility, check bin/pcsstidy for __DIR__ hardcoding issues on Windows; also, some deprecated notices persist in v2.2.0—run tests with -d display_errors=1 during deployment prep.
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport