{"id":92,"date":"2008-02-24T08:55:00","date_gmt":"2008-02-24T07:55:00","guid":{"rendered":"http:\/\/vince.tikasz.hu\/2008\/02\/26\/gyorsabb-javascript-es-css-letoltes\/"},"modified":"2011-07-24T15:14:02","modified_gmt":"2011-07-24T13:14:02","slug":"gyorsabb-javascript-es-css-letoltes","status":"publish","type":"post","link":"https:\/\/vince.tikasz.hu\/2008\/02\/24\/gyorsabb-javascript-es-css-letoltes\/","title":{"rendered":"Gyorsabb JavaScript \u00e9s CSS let\u00f6lt\u00e9s"},"content":{"rendered":"

Az \u00f6tlet<\/a>, ut\u00e1n megoldottuk a JavaScript t\u00f6m\u00f6r\u00edt\u00e9s\u00e9t<\/a> a JavaScript Packer<\/a>, majd a CSS t\u00f6m\u00f6r\u00edt\u00e9st<\/a> is a CSSTidy<\/a> seg\u00edts\u00e9g\u00e9vel.<\/p>\n

Most n\u00e9zz\u00fck a v\u00e9geredm\u00e9nyt, \u00e9s a haszn\u00e1lat\u00e1t<\/p>\n

\/**\r\n * headerFiles\r\n *\r\n * @param Array $files A gyorst\u00e1razand\u00f3 \u00e1llom\u00e1nyok list\u00e1ja\r\n * @param String $mode 'script|css'\r\n * @param String $fileType 'one|list'\r\n * @param String $prefix A  hivatkoz\u00e1s el\u00e9 sz\u00e1njuk\r\n * @param mixed $compress T\u00f6m\u00f6r\u00edt\u00e9s m\u00e9rt\u00e9ke\r\n * @copyright  Copyright (c) 2008 Vince Tikasz\r\n * @license    http:\/\/creativecommons.org\/licenses\/by-nc-sa\/2.5\/ Attribution-Noncommercial-Share Alike 2.5 Generic\r\n * @version    2008-02-25 08:30\r\n *\/\r\nfunction headerFiles( array $files, $mode, $fileType, $prefix, $compress = 62  ) {\r\n    if ( count( $files ) > 0) {\r\n        \/\/ Ha csak list\u00e1zunk, akkor a f\u00e1jlt\u00edpusnak megfelel\u0151 hivatkoz\u00e1st sz\u00farjuk be a k\u00f3dba\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                }\r\n                elseif ( $fileType == 'script' ) {\r\n                    echo '<script type=\"text\/javascript\" src=\"'. $prefix.$f.'\"><\/script>';\r\n                }\r\n            }\r\n        }\r\n        elseif ( $mode == 'one' ) {\r\n            \/\/\u00d6ssze\u00e1ll\u00edtjuk a kiszolg\u00e1land\u00f3 \u00e1llom\u00e1ny el\u00e9r\u00e9si \u00fatj\u00e1t \u00e9s nev\u00e9t\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\r\n            \/\/ Ha nem l\u00e9tezik, akkor a forr\u00e1sok valamelyike v\u00e1ltozott.\r\n            \/\/ Le kell gener\u00e1lni a kiszolg\u00e1land\u00f3 \u00e1llom\u00e1nyt\r\n            if ( !is_file( $fileName ) ) {\r\n                $Content = '';\r\n\r\n                \/\/ Beolvassuk az \u00e1llom\u00e1nyok tartalm\u00e1t\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\r\n                \/\/ \u00c9s a megfelel\u0151 eszk\u00f6zzel t\u00f6m\u00f6r\u00edtj\u00fck\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                    }\r\n                    elseif ( $compress == 62 || $compress == 'Normal' || $compress == 'high_compression' ) {\r\n                        $Css->load_template( 'high_compression' );\r\n                    }\r\n                    elseif ( $compress == 95 || $compress == 'High ASCII' || $compress == 'highest_compression' ) {\r\n                      $Css->load_template( 'highest_compression' );\r\n                    }\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\r\n                \/\/ A v\u00e9geredm\u00e9nyt elt\u00e1roljuk...\r\n                file_put_contents( $fileName, $Content );\r\n            }\r\n            \/\/ A m\u00e1r l\u00e9tez\u0151 \u00e1llom\u00e1nyt pedig kiszolg\u00e1ljuk\r\n            headerFiles( array( \"\/public\/cache\/{$name}.{$extension}\" ), 'list', $fileType, $prefix );\r\n        }\r\n    }\r\n}<\/pre>\n

Haszn\u00e1lat:<\/h3>\n

A k\u00f6nyvt\u00e1r szerkesztet:<\/p>\n

    \n
  • \/public\n
      \n
    • \/cache (Ide ker\u00fclnek a gener\u00e1lt, kiszolg\u00e1land\u00f3 \u00e1llom\u00e1nyok)<\/li>\n
    • \/script (A scriptek forr\u00e1s \u00e1llom\u00e1nyai)<\/li>\n
    • \/style (A CSS \u00e1llom\u00e1nyok)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n
      <?php\r\n$Scripts = array(\r\n    \/\/ mindig a jQuery, vagy az \u00e9ppen aktu\u00e1lisan haszn\u00e1lt k\u00f6nyvt\u00e1r az els\u0151\r\n     '\/public\/script\/jquery-1.2.3.js'\r\n    \/\/ jQuery Pluginok, Addonok\r\n    ,'\/public\/script\/jquery\/form.js'\r\n    ,'\/public\/script\/jquery\/superfish.js'\r\n    ,'\/public\/script\/jquery\/tablesorter.pack.js'\r\n    ,'\/public\/script\/jquery\/fckeditor.js'\r\n    ,'\/public\/script\/jquery\/delegate.js'\r\n    ,'\/public\/script\/jquery\/validate.js'\r\n\r\n    \/\/ \u00e9s az utols\u00f3 a saj\u00e1t script\r\n    ,'\/public\/script\/sajat.script.js'\r\n);\r\n$CSS = array(\r\n    ,'\/public\/style\/superfish.css'\r\n    ,'\/public\/style\/menu.css'\r\n    ,'\/public\/style\/selectbox.css'\r\n    ,'\/public\/style\/thickbox.css'\r\n    \/\/ saj\u00e1t CSS\r\n    ,'\/public\/style\/sajat.css'\r\n);\r\n\r\nheaderFiles( $Scripts, 'one', 'script' );\r\nheaderFiles( $CSS, 'one', 'css' );<\/pre>\n","protected":false},"excerpt":{"rendered":"

      Az \u00f6tlet, ut\u00e1n megoldottuk a JavaScript t\u00f6m\u00f6r\u00edt\u00e9s\u00e9t a JavaScript Packer, majd a CSS t\u00f6m\u00f6r\u00edt\u00e9st is a CSSTidy seg\u00edts\u00e9g\u00e9vel. Most n\u00e9zz\u00fck a v\u00e9geredm\u00e9nyt, \u00e9s a haszn\u00e1lat\u00e1t<\/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\/92"}],"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=92"}],"version-history":[{"count":0,"href":"https:\/\/vince.tikasz.hu\/wp-json\/wp\/v2\/posts\/92\/revisions"}],"wp:attachment":[{"href":"https:\/\/vince.tikasz.hu\/wp-json\/wp\/v2\/media?parent=92"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vince.tikasz.hu\/wp-json\/wp\/v2\/categories?post=92"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vince.tikasz.hu\/wp-json\/wp\/v2\/tags?post=92"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}