סמנכ"ל פיתוח, One Hour Translation
This time I will discuss something I wrote for myself.
So here comes the real headache...
We develop and code and debug and test and finally, it's deployment time. But wait! Shouldn't we combine all out JS source files into one file? And why not minify it on the way? Doing this over and over for each small change, it a pain.
Furthermore, what about different sections on out app that require different JS scripts? We surely don't want to serve the client with scripts he doesn't need!
So here is my solution:
How do you use it? It's quite simple. You just have to be familiar with PHP5.
git clone git://github.com/oyagev/PHP-JSLoader.git
1. First include or require the class file:
2. Everywhere we want to use this class, we have to retrieve its instance:
$jsloader = JSLoader::getInstance();
3. Next, we do one-time configuration:
The first line sets the absolute path to where the combined JS files will be placed. The second line sets a web available URL to the same directory.
The above line should go each time you need to include a js file and you should pass the absolute path to that file. Also remember to retrieve the class’s instance when needed. See section 2.
5. Finally, you should place a <script> tag to include the generated combined JS file. Fortunately, JSLoader does it for you. Just place this code (once) where needed:
6. Check your page source to see if the file was included and that it’s available.