{"id":88,"date":"2008-02-14T11:43:20","date_gmt":"2008-02-14T10:43:20","guid":{"rendered":"http:\/\/vince.tikasz.hu\/2008\/02\/14\/gyorsabb-javascript-es-css-letoltes-i\/"},"modified":"2011-07-24T15:15:32","modified_gmt":"2011-07-24T13:15:32","slug":"gyorsabb-javascript-es-css-letoltes-i","status":"publish","type":"post","link":"https:\/\/vince.tikasz.hu\/2008\/02\/14\/gyorsabb-javascript-es-css-letoltes-i\/","title":{"rendered":"Gyorsabb JavaScript \u00e9s CSS let\u00f6lt\u00e9s I."},"content":{"rendered":"

\u00c9pp egy nagyobb alkalmaz\u00e1st fejlesztek \u00e9pp, \u00e9s felmer\u00fclt, hogy a t\u00f6bb mint 10 JavaScript \u00e9s kb. 5 CSS \u00e1llom\u00e1nyt hogyan lehetne gyorsabban levar\u00e1zsolni a klienshez. Arra jutottam, hogy els\u0151 l\u00e9p\u00e9sben a k\u00e9r\u00e9sek sz\u00e1m\u00e1t kell cs\u00f6kkenteni. Magyarul f\u0171zz\u00fck \u00f6ssze egy \u00e1llom\u00e1nyba az \u00f6sszes JavaScriptet, \u00e9s egy m\u00e1sikba az \u00f6sszes CSS-t, ments\u00fck el, \u00e9s ha az utols\u00f3 lek\u00e9r\u00e9s \u00f3ta nem v\u00e1ltozott a forr\u00e1s \u00e1llom\u00e1nyok tartalma, akkor ezt a mentett \u00e1llom\u00e1nyt adjuk ki.<\/p>\n

A cs\u00f6kkent k\u00e9r\u00e9s-v\u00e1lasz sz\u00e1mon k\u00edv\u00fcl, m\u00e1sik — b\u00e1r nem olyan l\u00e1tv\u00e1nyos — el\u0151ny hogy a weblap fejl\u00e9c\u00e9ben \u00f6sszesen egy JS, \u00e9s egy Style hivatkoz\u00e1s lesz, ezzel is cs\u00f6kken a let\u00f6ltend\u0151 adat mennyis\u00e9ge.<\/p>\n

function headerFiles( array $files, $mode, $fileType, $prefix ) {\r\n    if ( count( $files ) > 0) {\r\n   \u00a0    if ( $mode == 'list' ) {\r\n   \u00a0   \u00a0    foreach ( $files as $f ) {\r\n   \u00a0   \u00a0   \u00a0    if ( $fileType == 'css' ) {\r\n   \u00a0   \u00a0   \u00a0   \u00a0    echo '<link rel=\"stylesheet\" type=\"text\/css\" href=\"'. $prefix.$f.'\" \/>';\r\n   \u00a0   \u00a0   \u00a0    }\r\n   \u00a0   \u00a0   \u00a0    elseif ( $fileType == 'script' ) {\r\n   \u00a0   \u00a0   \u00a0   \u00a0    echo '<script type=\"text\/javascript\" src=\"'. $prefix.$f.'\"><\/script>';\r\n   \u00a0   \u00a0   \u00a0    }\r\n   \u00a0   \u00a0    }\r\n   \u00a0    }\r\n   \u00a0    elseif ( $mode == 'one' ) {\r\n   \u00a0   \u00a0    $dirname = dirname($_SERVER['SCRIPT_FILENAME']);\r\n   \u00a0   \u00a0    $extension = $fileType == 'script' ? 'js' : 'css';\r\n   \u00a0   \u00a0    $Hashes = array();\r\n   \u00a0   \u00a0    foreach ( $files as $f ) {\r\n   \u00a0   \u00a0   \u00a0    $Hashes[] = sha1_file( $dirname.$f );\r\n   \u00a0   \u00a0    }\r\n   \u00a0   \u00a0    $name = sha1( join(';#%#;', $Hashes) );\r\n   \u00a0   \u00a0    $fileName = \"{$dirname}\/public\/cache\/{$name}.{$extension}\";\r\n   \u00a0   \u00a0    if ( !is_file( $fileName ) ) {\r\n   \u00a0   \u00a0   \u00a0    $Content = '';\r\n   \u00a0   \u00a0   \u00a0    foreach ( $files as $f ) {\r\n   \u00a0   \u00a0   \u00a0   \u00a0    if ( is_file( $dirname.$f ) ) {\r\n   \u00a0   \u00a0   \u00a0   \u00a0   \u00a0    $Content .= \"\/*START file: {$f}*\/\\n\";\r\n   \u00a0   \u00a0   \u00a0   \u00a0   \u00a0    $Content .= file_get_contents( $dirname.$f );\r\n   \u00a0   \u00a0   \u00a0   \u00a0   \u00a0    $Content .= \"\\n\/*\/\/END file: {$f}*\/\\n\";\r\n   \u00a0   \u00a0   \u00a0   \u00a0    }\r\n   \u00a0   \u00a0   \u00a0    }\r\n   \u00a0   \u00a0   \u00a0    file_put_contents( $fileName, $Content );\r\n   \u00a0   \u00a0    }\r\n   \u00a0   \u00a0    headerFiles( array( \"\/public\/cache\/{$name}.{$extension}\" ), 'list', $fileType, $prefix );\r\n   \u00a0    }\r\n    }\r\n}<\/pre>\n

Haszn\u00e1lat:<\/h3>\n
<?php\r\n$mode = 'list';\r\n\/\/$mode = 'one';\r\n\r\n$Scripts = array(\r\n    \/\/ mindig a jQuery az els\u00c5\u2018\r\n     '\/public\/jquery-1.2.3.js'\r\n    \/\/ jQuery Pluginok, Addonok\r\n    ,'\/public\/jquery\/form.js'\r\n    ,'\/public\/jquery\/superfish.js'\r\n    ,'\/public\/jquery\/tablesorter.pack.js'\r\n    ,'\/public\/jquery\/fckeditor.js'\r\n    ,'\/public\/jquery\/delegate.js'\r\n    ,'\/public\/jquery\/validate.js'\r\n\r\n    \/\/ \u00c3\u00a9s az utols\u00c3\u00b3 a saj\u00c3\u00a1t script\r\n    ,'\/public\/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\u00c3\u00a1t CSS\r\n    ,'\/public\/style\/sajat.css'\r\n);\r\necho '<?xml version=\"1.0\" encoding=\"UTF-8\" ?>'.\"\\n\";\r\n?><!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN\" \"http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd\">\r\n<html xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\r\n<head>\r\n    <meta http-equiv=\"Content-Type\" content=\"text\/html;charset=utf-8\" \/>\r\n    <title>TITLE<\/title>\r\n<?php\r\n    headerFiles( $Scripts, $mode, 'script', $this->baseUrl );\r\n    headerFiles( $CSS, $mode, 'css', $this->baseUrl );\r\n?>\r\n...<\/pre>\n","protected":false},"excerpt":{"rendered":"

\u00c9pp egy nagyobb alkalmaz\u00e1st fejlesztek \u00e9pp, \u00e9s felmer\u00fclt, hogy a t\u00f6bb mint 10 JavaScript \u00e9s kb. 5 CSS \u00e1llom\u00e1nyt hogyan lehetne gyorsabban levar\u00e1zsolni a klienshez. Arra jutottam, hogy els\u0151 l\u00e9p\u00e9sben a k\u00e9r\u00e9sek sz\u00e1m\u00e1t kell cs\u00f6kkenteni. Magyarul f\u0171zz\u00fck \u00f6ssze egy \u00e1llom\u00e1nyba … Continue reading →<\/span><\/a><\/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\/88"}],"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=88"}],"version-history":[{"count":0,"href":"https:\/\/vince.tikasz.hu\/wp-json\/wp\/v2\/posts\/88\/revisions"}],"wp:attachment":[{"href":"https:\/\/vince.tikasz.hu\/wp-json\/wp\/v2\/media?parent=88"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vince.tikasz.hu\/wp-json\/wp\/v2\/categories?post=88"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vince.tikasz.hu\/wp-json\/wp\/v2\/tags?post=88"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}