Version Notes
Enabled only for frontend
Download this release
Release Info
Developer | Razorphyn |
Extension | HTML_Compressor |
Version | 0.1.3 |
Comparing to | |
See all releases |
Code changes from version 0.1.2 to 0.1.3
- app/code/local/Razorphyn/HTMLCompressor/Model/Observer.php +9 -1
- app/code/local/Razorphyn/HTMLCompressor/Model/extime.log +0 -3
- app/code/local/Razorphyn/HTMLCompressor/etc/config.xml +9 -1
- app/etc/modules/Razorphyn_HTMLCompressor.xml +6 -0
- lib/Razorphyn/{html_compressor.php → HTMLCompressor/html_compressor.php} +8 -8
- package.xml +22 -6
app/code/local/Razorphyn/HTMLCompressor/Model/Observer.php
CHANGED
@@ -1,9 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
<?php
|
2 |
class Razorphyn_HTMLCompressor_Model_Observer
|
3 |
{
|
4 |
public function alterOutput($observer)
|
5 |
{
|
6 |
-
$lib_path = Mage::getBaseDir('lib').'/Razorphyn/html_compressor.php';
|
7 |
|
8 |
include_once($lib_path);
|
9 |
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* HTML Compressor
|
4 |
+
* Author: Razorphyn
|
5 |
+
* Suport Email: est.garndi@gmail.com
|
6 |
+
* Copyright: WTFPL(http://www.wtfpl.net/)
|
7 |
+
**/
|
8 |
+
?>
|
9 |
<?php
|
10 |
class Razorphyn_HTMLCompressor_Model_Observer
|
11 |
{
|
12 |
public function alterOutput($observer)
|
13 |
{
|
14 |
+
$lib_path = Mage::getBaseDir('lib').'/Razorphyn/HTMLCompressor/html_compressor.php';
|
15 |
|
16 |
include_once($lib_path);
|
17 |
|
app/code/local/Razorphyn/HTMLCompressor/Model/extime.log
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
2014-12-14T16:23:50+00:00 DEBUG (7): Execution time: 0.0063199996948242
|
2 |
-
2014-12-14T16:25:32+00:00 DEBUG (7): Execution time: 0.010541915893555
|
3 |
-
2014-12-14T16:25:49+00:00 DEBUG (7): Execution time: 0.0093181133270264
|
|
|
|
|
|
app/code/local/Razorphyn/HTMLCompressor/etc/config.xml
CHANGED
@@ -1,4 +1,10 @@
|
|
1 |
<?xml version="1.0"?>
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
<config>
|
3 |
<global>
|
4 |
<models>
|
@@ -6,6 +12,8 @@
|
|
6 |
<class>Razorphyn_HTMLCompressor_Model</class>
|
7 |
</HTMLCompressor>
|
8 |
</models>
|
|
|
|
|
9 |
<events>
|
10 |
<http_response_send_before>
|
11 |
<observers>
|
@@ -17,5 +25,5 @@
|
|
17 |
</observers>
|
18 |
</http_response_send_before>
|
19 |
</events>
|
20 |
-
</
|
21 |
</config>
|
1 |
<?xml version="1.0"?>
|
2 |
+
<!--/**
|
3 |
+
* HTML Compressor
|
4 |
+
* Author: Razorphyn
|
5 |
+
* Suport Email: est.garndi@gmail.com
|
6 |
+
* Copyright: WTFPL(http://www.wtfpl.net/)
|
7 |
+
**/-->
|
8 |
<config>
|
9 |
<global>
|
10 |
<models>
|
12 |
<class>Razorphyn_HTMLCompressor_Model</class>
|
13 |
</HTMLCompressor>
|
14 |
</models>
|
15 |
+
</global>
|
16 |
+
<frontend>
|
17 |
<events>
|
18 |
<http_response_send_before>
|
19 |
<observers>
|
25 |
</observers>
|
26 |
</http_response_send_before>
|
27 |
</events>
|
28 |
+
</frontend>
|
29 |
</config>
|
app/etc/modules/Razorphyn_HTMLCompressor.xml
CHANGED
@@ -1,4 +1,10 @@
|
|
1 |
<?xml version="1.0"?>
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
<config>
|
3 |
<modules>
|
4 |
<Razorphyn_HTMLCompressor>
|
1 |
<?xml version="1.0"?>
|
2 |
+
<!--/**
|
3 |
+
* HTML Compressor
|
4 |
+
* Author: Razorphyn
|
5 |
+
* Suport Email: est.garndi@gmail.com
|
6 |
+
* Copyright: WTFPL(http://www.wtfpl.net/)
|
7 |
+
**/-->
|
8 |
<config>
|
9 |
<modules>
|
10 |
<Razorphyn_HTMLCompressor>
|
lib/Razorphyn/{html_compressor.php → HTMLCompressor/html_compressor.php}
RENAMED
@@ -16,7 +16,7 @@
|
|
16 |
|
17 |
$search=array(
|
18 |
'@<(\s)*pre[^>]*>(?:[^<]+|)</pre>@', //Find PRE Tag
|
19 |
-
'@<(\s)*textarea(\b[^>]*?>[\\s\\S]*?</textarea>)\s*@' //Find TEXTAREA
|
20 |
);
|
21 |
$string=preg_replace_callback($search,
|
22 |
function($m){
|
@@ -32,17 +32,17 @@
|
|
32 |
$search = array(
|
33 |
'@( |\t|\f)+@', // Shorten multiple whitespace sequences
|
34 |
'@^\s+|\s+$@', // Trim lines
|
35 |
-
|
36 |
);
|
37 |
-
$replace = array(' ','',
|
38 |
|
39 |
$string = preg_replace($search, $replace, $string);
|
40 |
|
41 |
$search=array(
|
42 |
'@<!--\[if\s(?:[^<]+|<(?!!\[endif\]-->))*<!\[endif\]-->@', //Find IE Comments
|
43 |
-
'
|
44 |
'@//<!\[CDATA\[(?:[^<]+|)//]]>@', //Find CDATA
|
45 |
-
'
|
46 |
);
|
47 |
$string=preg_replace_callback($search,
|
48 |
function($m){
|
@@ -56,7 +56,7 @@
|
|
56 |
|
57 |
$search = array(
|
58 |
'@(class|id|value|alt|href|src|style|title)=(\'\s*?\'|"\s*?")@', //Remove empty attribute
|
59 |
-
'@<!--([\s\S]*?)-->@', // Strip comments
|
60 |
'@(\r\n|\n|\r)@', // Strip break line
|
61 |
'@( |\t|\f)+@', // Shorten multiple whitespace sequences
|
62 |
'@^\s+|\s+$@' // Trim lines
|
@@ -65,13 +65,13 @@
|
|
65 |
$string = preg_replace($search, $replace, $string);
|
66 |
|
67 |
//Remove blank lines
|
68 |
-
$string=preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/",
|
69 |
|
70 |
|
71 |
//Replace unique id with script, style, pre original tag
|
72 |
$c=count($idarray);
|
73 |
for($i=0;$i<$c;$i++){
|
74 |
-
$string = str_replace($idarray[$i][0],
|
75 |
}
|
76 |
|
77 |
return $string;
|
16 |
|
17 |
$search=array(
|
18 |
'@<(\s)*pre[^>]*>(?:[^<]+|)</pre>@', //Find PRE Tag
|
19 |
+
'@<(\s)*textarea(\b[^>]*?>[\\s\\S]*?</textarea>)\s*@', //Find TEXTAREA
|
20 |
);
|
21 |
$string=preg_replace_callback($search,
|
22 |
function($m){
|
32 |
$search = array(
|
33 |
'@( |\t|\f)+@', // Shorten multiple whitespace sequences
|
34 |
'@^\s+|\s+$@', // Trim lines
|
35 |
+
'@(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+@' //Remove blank lines
|
36 |
);
|
37 |
+
$replace = array(' ','',' ');
|
38 |
|
39 |
$string = preg_replace($search, $replace, $string);
|
40 |
|
41 |
$search=array(
|
42 |
'@<!--\[if\s(?:[^<]+|<(?!!\[endif\]-->))*<!\[endif\]-->@', //Find IE Comments
|
43 |
+
'@^(<)\s*?(script\b[^>]*?)(>)([\s\S]*?)(<)\s*(/\s*?script\s*)(>)$@', //Find SCRIPT Tag
|
44 |
'@//<!\[CDATA\[(?:[^<]+|)//]]>@', //Find CDATA
|
45 |
+
'@^(<)\s*?(style\b[^>]*?)(>)([\s\S]*?)(<)\s*(/\s*?style\s*)(>)$@' //Find STYLE Tag
|
46 |
);
|
47 |
$string=preg_replace_callback($search,
|
48 |
function($m){
|
56 |
|
57 |
$search = array(
|
58 |
'@(class|id|value|alt|href|src|style|title)=(\'\s*?\'|"\s*?")@', //Remove empty attribute
|
59 |
+
'@<!--([\s\S]*?)-->@', // Strip comments except IE
|
60 |
'@(\r\n|\n|\r)@', // Strip break line
|
61 |
'@( |\t|\f)+@', // Shorten multiple whitespace sequences
|
62 |
'@^\s+|\s+$@' // Trim lines
|
65 |
$string = preg_replace($search, $replace, $string);
|
66 |
|
67 |
//Remove blank lines
|
68 |
+
$string=preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/",' ', $string);
|
69 |
|
70 |
|
71 |
//Replace unique id with script, style, pre original tag
|
72 |
$c=count($idarray);
|
73 |
for($i=0;$i<$c;$i++){
|
74 |
+
$string = str_replace($idarray[$i][0], "\n".$idarray[$i][1]."\n", $string);
|
75 |
}
|
76 |
|
77 |
return $string;
|
package.xml
CHANGED
@@ -1,18 +1,34 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>HTML_Compressor</name>
|
4 |
-
<version>0.1.
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://www.wtfpl.net/">WTFPL</license>
|
7 |
<channel>community</channel>
|
8 |
<extends/>
|
9 |
-
<summary>Simple
|
10 |
-
<description>
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
<authors><author><name>Razorphyn</name><user>Razorphyn</user><email>est.grandi@gmail.com</email></author></authors>
|
13 |
<date>2014-12-18</date>
|
14 |
-
<time>
|
15 |
-
<contents><target name="
|
16 |
<compatible/>
|
17 |
<dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
|
18 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>HTML_Compressor</name>
|
4 |
+
<version>0.1.3</version>
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://www.wtfpl.net/">WTFPL</license>
|
7 |
<channel>community</channel>
|
8 |
<extends/>
|
9 |
+
<summary>Simple regex based HTML Compressor</summary>
|
10 |
+
<description>Simple regex based html compressor to reduce the html page size
|
11 |
+

|
12 |
+
It removes the following elements:
|
13 |
+
multiple white spaces
|
14 |
+
empty common attributes
|
15 |
+
empty lines
|
16 |
+
HTML comments
|
17 |
+

|
18 |
+

|
19 |
+
<p>and leaves untouched the following tags:
|
20 |
+
Script
|
21 |
+
Style
|
22 |
+
Pre
|
23 |
+
Textarea
|
24 |
+
CDATA
|
25 |
+
IE conditionals comments
|
26 |
+
</description>
|
27 |
+
<notes>Enabled only for frontend</notes>
|
28 |
<authors><author><name>Razorphyn</name><user>Razorphyn</user><email>est.grandi@gmail.com</email></author></authors>
|
29 |
<date>2014-12-18</date>
|
30 |
+
<time>19:16:07</time>
|
31 |
+
<contents><target name="mageetc"><dir><dir name="modules"><file name="Razorphyn_HTMLCompressor.xml" hash="85359f1f2fa391942e0618e4edbbcbf4"/></dir></dir></target><target name="magelocal"><dir name="Razorphyn"><dir name="HTMLCompressor"><dir name="Model"><file name="Observer.php" hash="c8a7658d22159fcbeee8c75443cce021"/></dir><dir name="etc"><file name="config.xml" hash="dfeef644720af3338fcba106a0a5529b"/></dir></dir></dir></target><target name="magelib"><dir><dir name="Razorphyn"><dir name="HTMLCompressor"><file name="html_compressor.php" hash="ff87eacce1a396dc4e1fb6360add9d04"/></dir></dir></dir></target></contents>
|
32 |
<compatible/>
|
33 |
<dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
|
34 |
</package>
|