定制 grip/trimfilter 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

grip/trimfilter

最新稳定版本:1.0.0

Composer 安装命令:

composer require grip/trimfilter

包简介

HTML whitespace filter for PHP

README 文档

README

This library provides an HTML whitespace filter that you can use to filter out unneeded whitespace from generated HTML. It does not buffer the whole page so it will not hurt your time-to-first-byte (TTFB). Some buffering is required, but you can set the buffer size yourself. A buffer of around 500 bytes is recommended. Contents of <script> / <style> / <textarea> / <pre> and comment tags are never trimmed.

Example

This filter turns this

<!DOCTYPE html>

<html lang="nl">

    <head>
    	<meta charset="utf-8">

	<title>Online koploper worden | Grip Online</title>

	<meta name="generator" content="e-Grip">
	<meta name="description" content="Grip Online helpt uw bedrijf bij de essentiële uitdaging om in uw branche online koploper te worden of te blijven. Van e-commerce tot corporate, van sites tot apps. Kennismaken met Grip?">



	<link rel="shortcut icon" href="/assets/grip_online/favicon.png">
	<link rel="icon" type="image/png" sizes="192x192" href="/assets/grip_online/images/default/favicon-192x192.png">
	<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="/assets/grip_online/images/default/apple-touch-icon-180x180.png">
	<link rel="home" href="/" title="Homepage">

	<link rel="stylesheet" href="/assets/grip_online/css/default/screen.css">
</head>

    <body>


    <div id="container">


        <div id="header" class="site-header">

into this:

<!DOCTYPE html>
<html lang="nl">
<head>
<meta charset="utf-8">
<title>Online koploper worden | Grip Online</title>
<meta name="generator" content="e-Grip">
<meta name="description" content="Grip Online helpt uw bedrijf bij de essentiële uitdaging om in uw branche online koploper te worden of te blijven. Van e-commerce tot corporate, van sites tot apps. Kennismaken met Grip?">
<link rel="shortcut icon" href="/assets/grip_online/favicon.png">
<link rel="icon" type="image/png" sizes="192x192" href="/assets/grip_online/images/default/favicon-192x192.png">
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="/assets/grip_online/images/default/apple-touch-icon-180x180.png">
<link rel="home" href="/" title="Homepage">
<link rel="stylesheet" href="/assets/grip_online/css/default/screen.css">
</head>
<body>
<div id="container">
<div id="header" class="site-header">

Installing

The library can be installed using Composer:

$ composer require grip/trimfilter

Usage

Example usage with Twig template rendering:

$trimFilter = new Grip\HtmlWhitespaceFilter();

ob_start(array($trimFilter, 'filter'), 500);

$template = $twig->load('index.html');
$template->display(['the' => 'variables', 'go' => 'here']);

ob_end_flush();

$trimFilter->endFlush();

Caveats

This library only works with with single-byte character encodings and UTF-8.

Background

We like our HTML as clean as possible. When working with a template engine (such as Twig), indenting template tags can introduce a whole lot of whitespace in the output. That's why we created this filter in the first place. Other than that, most whitespace in HTML can be seen as 'waste'. It may be true that the excessive whitespace compresses quite well using gzip or brotli, but on the client side it will be sent uncompressed to the HTML parser.

统计信息

  • 总下载量: 1.01k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2024-03-08