Rose debug info
---------------

OpenCart: как минифицировать HTML

Для более быстрой загрузки страниц.

Что делать

  1. Открываем сайт/system/library/response.php
  1. Находим код (~108 строка):
public function output() {
	if ($this->output) {
		$output = $this->level ? $this->compress($this->output, $this->level) : $this->output;
		
		if (!headers_sent()) {
			foreach ($this->headers as $header) {
				header($header, true);
			}
		}
		
		echo $output;
	}
}
  1. Заменяем на:
public function output() {
 
if ($this->output) {
    $this->output = preg_replace("/(\n)+/", "\n", $this->output);
    $this->output = preg_replace("/\r\n+/", "\n", $this->output);
    $this->output = preg_replace("/\n(\t)+/", "\n", $this->output);
    $this->output = preg_replace("/\n(\ )+/", "\n", $this->output);
    $this->output = preg_replace("/\>(\n)+</", '><', $this->output);
    $this->output = preg_replace("/\>\r\n</", '><', $this->output);
}

if ($this->output) {
	$output = $this->level ? $this->compress($this->output, $this->level) : $this->output;
	
	if (!headers_sent()) {
		foreach ($this->headers as $header) {
			header($header, true);
		}
	}
	
	echo $output;
}
}
  1. Сохраняем, обновляем кэш.
  1. Готово.
Поделиться
Отправить
 1209   2020   OpenCart 3   работа