-
Notifications
You must be signed in to change notification settings - Fork 87
/
autoptimize_helper.php_example
143 lines (113 loc) · 5.33 KB
/
autoptimize_helper.php_example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
/*
Plugin Name: Autoptimize Helper
Plugin URI: http://blog.futtta.be/autoptimize
Description: Autoptimize Helper contains some helper functions to make Autoptimize even more flexible
Author: Frank Goossens (futtta)
Version: 0.2
Author URI: http://blog.futtta.be/
*/
/* autoptimize_filter_css_datauri_maxsize: change the threshold at which background images are turned into data uri's;
@param $urisize: default size
@return: your own preferred size */
// add_filter('autoptimize_filter_css_datauri_maxsize','my_ao_override_dataursize',10,1);
function my_ao_override_dataursize($urisizeIn) {
return 100000;
}
/* autoptimize_filter_css_datauri_exclude: exclude background images from being turned into data uri's;
@param $imageexcl: default images excluded (empty)
@return: comma-seperated list of images to exclude */
// add_filter('autoptimize_filter_css_datauri_exclude','my_ao_exclude_image',10,1);
function my_ao_exclude_image($imageexcl) {
return $imageexcl . ", adfreebutton.jpg, otherimage.png";
}
/* autoptimize_filter_js_defer: change flag added to javascript
@param $defer: default value, "" when forced in head, "defer " when not forced in head
@return: new value */
// add_filter('autoptimize_filter_js_defer','my_ao_override_defer',10,1);
function my_ao_override_defer($defer) {
return $defer."async ";
}
/* autoptimize_filter_noptimize: stop autoptimize from optimizing, e.g. based on URL as in example
@return: boolean, true or false */
// add_filter('autoptimize_filter_noptimize','my_ao_noptimize',10,1);
function my_ao_noptimize( $flag_in ) {
if (strpos($_SERVER['REQUEST_URI'],'no-autoptimize-now')!==false) {
return true;
} else {
return $flag_in;
}
}
/* autoptimize_filter_js_exclude; JS optimization exclude strings, as configured in admin page
@param $exclude: comma-seperated list of exclude strings
@return: comma-seperated list of exclude strings */
// add_filter('autoptimize_filter_js_exclude','my_ao_override_jsexclude',10,1);
function my_ao_override_jsexclude($exclude) {
return $exclude.", customize-support";
}
/* autoptimize_filter_css_exclude: CSS optimization exclude strings, as configured in admin page
@param $exclude: comma-seperated list of exclude strings
@return: comma-seperated list of exclude strings */
// add_filter('autoptimize_filter_css_exclude','my_ao_override_cssexclude',10,1);
function my_ao_override_cssexclude($exclude) {
return $exclude.", recentcomments";
}
/* autoptimize_filter_js_movelast: internal array of what script can be moved to the bottom of the HTML
@param array $movelast
@return: updated array */
// add_filter('autoptimize_filter_js_movelast','my_ao_override_movelast',10,1);
function my_ao_override_movelast($movelast) {
$movelast[]="console.log";
return $movelast;
}
/* autoptimize_filter_css_replacetag: where in the HTML is optimized CSS injected
@param array $replacetag, containing the html-tag and the method (inject "before", "after" or "replace")
@return array with updated values */
// add_filter('autoptimize_filter_css_replacetag','my_ao_override_css_replacetag',10,1);
function my_ao_override_css_replacetag($replacetag) {
return array("<head>","after");
}
/* autoptimize_filter_js_replacetag: where in the HTML is optimized JS injected
@param array $replacetag, containing the html-tag and the method (inject "before", "after" or "replace")
@return array with updated values */
// add_filter('autoptimize_filter_js_replacetag','my_ao_override_js_replacetag',10,1);
function my_ao_override_js_replacetag($replacetag) {
return array("<injectjs />","replace");
}
/* autoptimize_js_do_minify: do we want to minify? if set to false autoptimize effectively only aggregates, but does not minify
@return: boolean true or false */
// add_filter('autoptimize_js_do_minify','my_ao_js_minify',10,1);
function my_ao_js_minify() {
return false;
}
/* autoptimize_css_do_minify: do we want to minify? if set to false autoptimize effectively only aggregates, but does not minify
@return: boolean true or false */
// add_filter('autoptimize_css_do_minify','my_ao_css_minify',10,1);
function my_ao_css_minify() {
return false;
}
/* autoptimize_js_include_inline: do we want AO to also aggregate inline JS?
@return: boolean true or false */
// add_filter('autoptimize_js_include_inline','my_ao_js_include_inline',10,1);
function my_ao_js_include_inline() {
return false;
}
/* autoptimize_css_include_inline: do we want AO to also aggregate inline CSS?
@return: boolean true or false */
// add_filter('autoptimize_css_include_inline','my_ao_css_include_inline',10,1);
function my_ao_css_include_inline() {
return false;
}
/* autoptimize_filter_css_defer_inline: what CSS to inline when "defer and inline" is activated
@param $inlined: string with above the fold CSS as configured in admin
@return: updated string with above the fold CSS */
// add_filter('autoptimize_filter_css_defer_inline','my_ao_css_defer_inline',10,1);
function my_ao_css_defer_inline($inlined) {
return $inlined."h2,h1{color:red !important;}";
}
/* autoptimize_filter_css_fonts_cdn: do we want to move fonts to the CDN-url as well
@return: false (default) or true */
// add_filter('autoptimize_filter_css_fonts_cdn','my_css_cdnfont',10,0);
function my_css_cdnfont(){
return true;
}