compression_test()
Test support for compressing JavaScript from PHP
Description Description
Outputs JavaScript that tests if compression from PHP works as expected and sets an option with the result. Has no effect when the current user is not an administrator. To run the test again the option ‘can_compress_scripts’ has to be deleted.
Source Source
File: wp-admin/includes/template.php
2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 | function compression_test() { ?> <script type= "text/javascript" > var compressionNonce = <?php echo wp_json_encode( wp_create_nonce( 'update_can_compress_scripts' ) ); ?>; var testCompression = { get : function (test) { var x; if ( window.XMLHttpRequest ) { x = new XMLHttpRequest(); } else { try {x= new ActiveXObject( 'Msxml2.XMLHTTP' );} catch (e){ try {x= new ActiveXObject( 'Microsoft.XMLHTTP' );} catch (e){};} } if (x) { x.onreadystatechange = function () { var r, h; if ( x.readyState == 4 ) { r = x.responseText. substr (0, 18); h = x.getResponseHeader( 'Content-Encoding' ); testCompression.check(r, h, test); } }; x.open( 'GET' , ajaxurl + '?action=wp-compression-test&test=' +test+ '&_ajax_nonce=' +compressionNonce+ '&' +( new Date ()).getTime(), true); x.send( '' ); } }, check : function (r, h, test) { if ( ! r && ! test ) this.get(1); if ( 1 == test ) { if ( h && ( h.match(/deflate/i) || h.match(/gzip/i) ) ) this.get( 'no' ); else this.get(2); return ; } if ( 2 == test ) { if ( '"wpCompressionTest' == r ) this.get( 'yes' ); else this.get( 'no' ); } } }; testCompression.check(); </script> <?php } |
Expand full source code Collapse full source code View on Trac
Changelog Changelog
Version | Description |
---|---|
2.8.0 | Introduced. |