{"id":537,"date":"2014-06-11T20:44:52","date_gmt":"2014-06-11T20:44:52","guid":{"rendered":"http:\/\/localhost\/__sites\/3d_blog\/?p=537"},"modified":"2014-06-11T20:57:05","modified_gmt":"2014-06-11T20:57:05","slug":"server-side-js-concatenation","status":"publish","type":"post","link":"https:\/\/blog.silverterra.net\/?p=537","title":{"rendered":"server side js\/css concatenation"},"content":{"rendered":"<blockquote><p>Goal: combine js files on the server side<\/p><\/blockquote>\n<p>I like to work with independent files. One javascript object one file. This is easy, but to get these files is not.<br \/>\nHere is a simple server side script to create one js file from the many. For example the name is <strong>main.php<\/strong>.<\/p>\n<p><strong>1. for js files<\/strong><\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">\r\nheader('Content-type: text\/javascript; charset=utf-8'); \r\n$dir = '..\/js';\r\n$arr = scandir($dir);\r\nforeach($arr as $val) {\r\n  if(strpos($val, '_') === 0){\r\n    include($val);\r\n  }\r\n}\r\n<\/pre>\n<p>This file contains every js file (name starting with _ \/underscore\/ ) from the specified directory.<br \/>\nWith this simple name trick I can filter easy my files from the output.<\/p>\n<p>Be careful this is only a simple file concatenation!<\/p>\n<p>Of course this method is usable for css files as well like this. Just we need to change the content type and the source directory.<\/p>\n<p><strong>1. for css files<\/strong><\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">\r\nheader('Content-type: text\/css; charset=utf-8'); \r\n$dir = '..\/css';\r\n$arr = scandir($dir);\r\nforeach($arr as $val) {\r\n  if(strpos($val, '_') === 0){\r\n    include($val);\r\n  }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Goal: combine js files on the server side I like to work with independent files. One javascript object one file. This is easy, but to get these files is not. Here is a simple server side script to create one js file from the many. For example the name is main.php. 1. for js files [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-537","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts\/537","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=537"}],"version-history":[{"count":6,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts\/537\/revisions"}],"predecessor-version":[{"id":543,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts\/537\/revisions\/543"}],"wp:attachment":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=537"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=537"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=537"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}