Skip to content

dlundgren/php-css-splitter

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Css Splitter

Build Status

Splits stylesheets that go beyond the IE limit of 4096 selectors. See this MSDN blog post for more information about this.

Installation

It's recommended to use Composer to install

$ composer require dlundgren/php-css-splitter

This will install the CssSplitter library and any required dependencies.

Usage

The default max selectors is 4095.

$splitter = new \CssSplitter\Splitter();
// Load your css file
$css = file_get_contents('styles.css');

// Skip the first part as the Internet Explorer interprets your css until it reaches the limit
$selector_count = $splitter->countSelectors($css) - 4095;
// Calculate how many additional parts we need to create
$additional_part_count =  ceil($selector_count / 4095);

if($additional_part_count > 0) {
	// Loop and create the additional parts
	// Add an offset of two as we are creating the css from the second part on
	for($part = 2; $part < $additional_part_count + 2; $part++) {
		// Create or update the css files
		file_put_contents('styles_'. $part .'.css', $splitter->split($css, $part));
	}
}

Credits & License

Original inspiration came from the Ruby gem CssSplitter.

CssSplitter is licensed under the MIT license. See License File for more information.

About

PHP Css Splitter

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •