{"id":90,"date":"2008-02-16T09:25:49","date_gmt":"2008-02-16T08:25:49","guid":{"rendered":"http:\/\/vince.tikasz.hu\/2008\/02\/16\/gyorsabb-js-es-css-iii\/"},"modified":"2011-07-24T15:14:40","modified_gmt":"2011-07-24T13:14:40","slug":"gyorsabb-js-es-css-iii","status":"publish","type":"post","link":"https:\/\/vince.tikasz.hu\/2008\/02\/16\/gyorsabb-js-es-css-iii\/","title":{"rendered":"Gyorsabb JS \u00e9s CSS III."},"content":{"rendered":"
M\u00e1r el\u00e9rt\u00fck, hogy csak egy \u00e1llom\u00e1nyt<\/a> kell kiszolg\u00e1lni. M\u00e1r t\u00f6m\u00f6r\u00edtett\u00fcnk<\/a> a JavaScript k\u00f3dot is. K\u00f6vetkezik a CSS k\u00f3d t\u00f6m\u00f6r\u00edt\u00e9se. Szerencs\u00e9re m\u00e1r erre a feladatra is l\u00e9tezik k\u00e9sz megold\u00e1s a CSSTidy<\/a> form\u00e1j\u00e1ban. Haszn\u00e1lata a JS t\u00f6m\u00f6r\u00edt\u0151h\u00f6z hasonl\u00f3an egyszer\u0171 \u00c9s a m\u00f3dos\u00edt\u00e1sok ut\u00e1n a \u00edgy n\u00e9z ki a f\u00fcggv\u00e9ny\u00fcnk:<\/p>\n M\u00e1r el\u00e9rt\u00fck, hogy csak egy \u00e1llom\u00e1nyt kell kiszolg\u00e1lni. M\u00e1r t\u00f6m\u00f6r\u00edtett\u00fcnk a JavaScript k\u00f3dot is. K\u00f6vetkezik a CSS k\u00f3d t\u00f6m\u00f6r\u00edt\u00e9se. Szerencs\u00e9re m\u00e1r erre a feladatra is l\u00e9tezik k\u00e9sz megold\u00e1s a CSSTidy form\u00e1j\u00e1ban. Haszn\u00e1lata a JS t\u00f6m\u00f6r\u00edt\u0151h\u00f6z hasonl\u00f3an egyszer\u0171<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,23,28,13],"tags":[63,74,83,68],"_links":{"self":[{"href":"https:\/\/vince.tikasz.hu\/wp-json\/wp\/v2\/posts\/90"}],"collection":[{"href":"https:\/\/vince.tikasz.hu\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vince.tikasz.hu\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vince.tikasz.hu\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vince.tikasz.hu\/wp-json\/wp\/v2\/comments?post=90"}],"version-history":[{"count":0,"href":"https:\/\/vince.tikasz.hu\/wp-json\/wp\/v2\/posts\/90\/revisions"}],"wp:attachment":[{"href":"https:\/\/vince.tikasz.hu\/wp-json\/wp\/v2\/media?parent=90"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vince.tikasz.hu\/wp-json\/wp\/v2\/categories?post=90"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vince.tikasz.hu\/wp-json\/wp\/v2\/tags?post=90"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}
\n<\/p>\n$in = file_get_contents( 'my.css' );\r\n\r\nrequire 'class.csstidy.php';\r\n$Css = new csstidy();\r\n$Css->load_template( 'high_compression' );\r\n$Css->parse( $in );\r\n\r\n$out = $Css->print->plain();\r\nfile_put_contents( 'my.compressed.css', $out );<\/pre>\n
function headerFiles( array $files, $mode, $fileType, $prefix, $compress = 62 )\r\n{\r\n if ( count( $files ) > 0) {\r\n if ( $mode == 'list' ) {\r\n foreach ( $files as $f ) {\r\n if ( $fileType == 'css' ) {\r\n echo '<link rel=\"stylesheet\" type=\"text\/css\" href=\"'. $prefix.$f.'\" \/>';\r\n } elseif ( $fileType == 'script' ) {\r\n echo '<script type=\"text\/javascript\" src=\"'. $prefix.$f.'\"><\/script>';\r\n }\r\n }\r\n } elseif ( $mode == 'one' ) {\r\n $dirname = dirname($_SERVER['SCRIPT_FILENAME']);\r\n $extension = $fileType == 'script' ? 'js' : 'css';\r\n $Hashes = array();\r\n foreach ( $files as $f ) {\r\n $Hashes[] = sha1_file( $dirname.$f );\r\n }\r\n $name = sha1( join(';#%#;', $Hashes) );\r\n $fileName = \"{$dirname}\/public\/cache\/{$name}.{$extension}\";\r\n if ( !is_file( $fileName ) ) {\r\n $Content = '';\r\n foreach ( $files as $f ) {\r\n if ( is_file( $dirname.$f ) ) {\r\n $Content .= \"\/*START file: {$f}*\/\\n\";\r\n $Content .= file_get_contents( $dirname.$f );\r\n $Content .= \"\\n\/*\/\/END file: {$f}*\/\\n\";\r\n }\r\n }\r\n if ( $fileType == 'script' && strval(0) != strval($compress) ) {\r\n require_once( 'class.JavaScriptPacker.php' );\r\n $packer = new JavaScriptPacker($Content, $compress, true, false);\r\n $Content = $packer->pack();\r\n }\r\n elseif ( $fileType == 'css' && strval(0) != strval($compress) ) {\r\n require 'csstidy\/class.csstidy.php';\r\n $Css = new csstidy();\r\n\r\n $Css->set_cfg('remove_bslash', 1 );\r\n $Css->set_cfg('compress_colors', 1 );\r\n $Css->set_cfg('compress_font-weight', 1 );\r\n $Css->set_cfg('optimise_shorthands', 1 );\r\n $Css->set_cfg('remove_last_;' , false );\r\n $Css->set_cfg('case_properties' , 1 );\r\n $Css->set_cfg('merge_selectors', 2 );\r\n $Css->set_cfg('css_level', 'CSS2.1' );\r\n\r\n if ( $compress == 10 || $compress == 'Numeric' || $compress == 'low_compression' ) {\r\n $Css->load_template( 'low_compression' );\r\n } elseif ( $compress == 62 || $compress == 'Normal' || $compress == 'high_compression' ) {\r\n $Css->load_template( 'high_compression' );\r\n } elseif ( $compress == 95 || $compress == 'High ASCII' || $compress == 'highest_compression' ) {\r\n $Css->load_template( 'highest_compression' );\r\n } else {\r\n $Css->load_template( 'default' );\r\n }\r\n $Css->parse( $Content );\r\n $Content = $Css->print->plain();\r\n }\r\n file_put_contents( $fileName, $Content );\r\n }\r\n headerFiles( array( \"\/public\/cache\/{$name}.{$extension}\" ), 'list', $fileType, $prefix );\r\n }\r\n }\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"