Skip to content

Php package to compress HTML, remove CSS and Javascript for web crawlers.

License

Notifications You must be signed in to change notification settings

doncadavona/html_minifier

Repository files navigation

This is a work in Progress

HTML Minifier

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

A PHP package to minify HTMLs, Javascripts and CSSs. Supports PSR-4 Autoloader.

Install

Via Composer

$ composer require doncadavona/html_minifier

Usage

use DonCadavona\HtmlMinifier\HtmlMinifier;

// Sample HTML string
$html = '
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style type="text/css">
		html {
			padding-top: 20px;
		}
		body {
			margin: 0px;
		}
	</style>
</head>
<body>
	<h1>Hello World</h1>
	<script>
		// This is single-line a comment.
		/* This is a
		multi-line 
		comment. */
		/**
		 * This is a doc block comment.
		 */
	</script>
</body>
</html>
';

// Minify the HTML
echo HtmlMinifier::minify($html);

// <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Document</title><style type="text/css"> html { padding-top: 20px; } body { margin: 0px; } </style></head><body><h1>Hello World</h1><script></script></body></html>

// Minify the HTML and remove JavaScripts and CSSs:
echo HtmlMinifier::minify($html, true, true);

// <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Document</title></head><body><h1>Hello World</h1></body></html>

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please email dcadavona@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

About

Php package to compress HTML, remove CSS and Javascript for web crawlers.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages