Download the PHP package momentum81/php-remove-unused-css without Composer

On this page you can find all versions of the php package momentum81/php-remove-unused-css. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-remove-unused-css

Overview

PHP Remove Unused CSS is a tool to remove unused CSS from your website using PHP. Developed by Momentum 81 - https://momentum81.com.

The main idea is to first compile your CSS into as few files as possible, then you would remove the extra classes using this package, then use this (or another) package to minify the CSS.

Often this is done with JS however that can raise issues if you want to work this into a pure PHP development flow.

Installation

Installation via composer:

Example

Classes

The are two main ways of using the package:

Basic Class

The basic class is created using RemoveUnusedCssBasic. This is essentially a 'dumb' system that won't traverse the DOM in any way and will just include a selector if it's lowest level appears in the CSS.

That said, this can still provide some significant savings in file size, especially when you're using a package like Bootstrap.

The basic class only weakly matches, lets look at the following HTML:

The following CSS Classes would match and be kept, despite the .hello class being used in the HTML not being inside a parent element using the class .test:

Complete Class

In Development. This method attempts to be smarter and where possible traverse the DOM as much as it can (When using a templating system this is infinitely more difficult if your views are not cached, so the system can only do so well here).

Available Methods

Method Description
whitelist(...$selectors) Here you can provice multipleCSS selectors to whitelist, ensuring they remain in the CSS even if they are not present in the HTML.
styleSheets(...$styleSheets) Here you can provide glob compatible absolute paths to the stylesheets you want to refactor. For example in Laravel, you could use public_path('**/*.css').
htmlFiles(...$htmlFiles) Here you can provide glob compatible absolute paths to the HTML files (Can be any text file type, not just .html) that you want to scan for selectors to keep in your refactored CSS. For example in Laravel, you could use resource_path('**/*.blade.php').
setFilenameSuffix($string) By default the platform will overwrite the stylesheets it finds (When saving as files), here you can provide a suffix for the file name - this will get appended before the file type. So stylesheet.css could become stylesheet.refactored.min.css. The default value is .refactored.min. IMPORTANT: If you do not specify this method, your original files will be OVERWRITTEN if you use saveFiles()!
minify($bool) If specified, this will perform minification on the CSS before it's saved/returned, using the package matthiasmullie/minify (https://github.com/matthiasmullie/minify)
skipComment($bool) Specify if we should skip the comment at the top of the CSS file
comment($string) Specify custom text for the comment at the top of the CSS file - use the variable :time: for the date and time to be added in its place. Don't forget to add your opening and closing tags for the comment: /* and */.
refactor() This method performs the refactoring.
saveFiles() This will save the new (Or overwritten) files
returnAsText() This will return the refactored CSS as an array of files with text rather than writing them to real files.

All versions of php-remove-unused-css with dependencies

PHP Build Version
Package Version
Requires php Version ^7.2
matthiasmullie/minify Version ^1.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package momentum81/php-remove-unused-css contains the following files

Loading the files please wait ....