Automatic javascript generation on constantly changing websites

This time I will discuss something I wrote for myself.

The problem:

I'm (and maybe you are) constantly developing my application, adding features and closing bugs, both to PHP and Javascript pages. When it comes to PHP, there is no issue, we simply update the last version to the server and forget about it.
With Javascript, however, this is a bit more complicated.

To fully understand the situation, place yourself into the CTO's shoes. We want bugs closed, we want new tricks and we want it to work and fast. When it comes to performance, the first (or second) rule in the book is to minimize and minify javascript files that the website works with. Why?

  1. Each javascript file we load with the <script> tag is actually causing the client's browser to create a separate request to fetch it. Multiple requests are huge overhead, that's why we want to load as little as possible JS files.
  2. Each javascript file contains unnecessary characters like newline, tabs, comment etc. Why not remove them? This process is called minification and it can shrink the JS file by 20-30% while keeping it fully functional. Great!

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:

I created the JSLoader class, which takes care of generating a combined javascript files according to the JS sources needed for a specific section, minify it and serve it to the client. It will cache the combined JS files for later, so the same combinations will not be re-generated. Nevertheless, if you change one byte in any JS file, it will re-generate the appropriate files.

How do you use it? It's quite simple. You just have to be familiar with PHP5.

Installation:

  1. Create a web-available folder for the generated Javascript files.
  2. Give the above folder write permissions for PHP.
  3. Copy the JSLoader package to your project or clone it from:
    git clone git://github.com/oyagev/PHP-JSLoader.git

How-To:

1. First include or require the class file:
require_once '../lib/JSLoader.php';

2. Everywhere we want to use this class, we have to retrieve its instance:
$jsloader = JSLoader::getInstance();

3. Next, we do one-time configuration:

$jsloader->setJavascriptFolder('/home/user/public/html/my_website/js'); 
$jsloader->setJavascriptFolderURL('<a href="https://www.my-website.com/js'">https://www.my-website.com/js'</a>);

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.

4. Now here is the real thing! Everywhere you want to “include” a javascript file, you do:
$jsloader->add('/absolute/path/to/file.js');

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:
$jsloader->putScriptTag();

6. Check your page source to see if the file was included and that it’s available.

Comments

great blog

Нello! I simрlу wаnt to give you а big thumbs up foг the great informаtion you've got here on this post. I will be returning to your blog for more soon.

Also visit my page server for cardsharing

[p]Those days are gone when sun glasses ended up simply employed to take care of a people eye-sight from sun rays . Not absolutely everyone has exactly the same deal with shape and which is what helps make us all exclusive . Cheap Oakley Sunglasses - Greatest Sunglasses for Fashion Mindful Women

The first actually fashion house of luxurious ready-to-wear, Oakley has come quite a distance after [url=http://www.ccheapsunglasses4u.com]cheap oakley sunglasses for men[/url] its inception within 1952 in Paris . Should you understand what the substantial or higher finish is you might have the ability to better shop for that reduced costs you need . These umbrellas are approximately, and tend to get [url=http://www.ccheapsunglasses4u.com]cheap oakley polarized sunglasses

[/url] scaled-down in measurement having a flatter canopy . Keep in mind here that if impressing people is a concern the Oakley THUMP couldn't be more capable of the task . What comes to your mind while getting to know these free eyeglasses

">

If you this kind of people who work at computer for a lot of time each day, you must take care of your eyes [url=http://www.ccheapsunglasses4u.com]cheap oakley sunglasses sale[/url] because computer radiation are likely to destroy your eyes . Oakley Sunglasses Sale

Related Articles - Oakley Sunglasses Sale, Oakley Sunglasses Cheap, Oakley Sunglasses Outlet,

Email this Article to a Friend!

Receive Articles like this one direct to your email [url=http://www.ccheapsunglasses4u.com]cheap fake oakley sunglasses[/url] box!Subscribe for free today! . Step 2: Styles and features Various styles and features of Coach sunglasses must be studied through authentic catalogs.[/p][p]This is based about the company's stellar reputation [url=http://www.ccheapsunglasses4u.com]cheap oakley sunglasses[/url] and nothing otherwise . A pair of Oakley sunglasses are an absolute must have for all who don't comprise in route they look . Truth be told, whether it??s the cool blue half jacket silver ice or the silver sunglasses, many work switches into making the fake oakley sunglasses look very, very real . Adjustable nose pads and wide temples offer a comfy fit . Therefore, if you have decided to purchase your pair, you can easily place an order from among the

nearest store of branded authentic designer sunglasses or buy one online . A one page would not be enough o covers the interesting facts about Oakley sunglasses . Early portable CD players were't actually all that portable ' If you had one and ever moved to sharply while using it you'll know what I mwean! Now with mp3 players & ipods there are no moving parts so you can listen when working out, running or anything else where a CD player would be useless . Retain in head that it really is essential that you just decide on a style that fits you and brings out the best of your facial functions.[/p]

Live Telecast of boxing match between Dereck Chisora vs.
Wladimir Klitschko
now easily obtainable online. Internet boxing fight
is available on your
personal computers from which you can record the stunning acts
which enable it to replay
the awesome actions perform with the boxer. All this is accessible to you at free
of cost and you'll be able to easily benefit from the live
performances without breaks and
intermission. There are numerous websites and software
available where you'll be able to
easily watch your struggle. The fight has grown to be more
interesting because the best
boxers will be in the ring now. Dereck Chisora,
the award winner of common
wealth games and so on the other side Wladimir Klitscho, powerful and vigorous
champion of the world will fight collectively and make a long lasting
history.
When the both boxers appear in the ring and from their fighting
match the
fans is sure to become more excited and crazy to observe them and they also use
every source to possess one look of their live match.
Klitschko vs. Chisora
Live Stream might help the
viewers to see the live match at once without any interruption and
intermissions. If you desire to watch the match online at your home, with your
friends then you certainly should have your personal computer
and a good internet
connection. The fighters have got up many dangerous and
high fights and
every time their fans have praised their capability and performance.

The demand of online watch has grown these days and remember the
need and requirement of the general public many live stream sites and links ahs
established online that's easily accessible and viewable.
It’s became easy
for the public to view deadly boxing fights of their favorite fighter.

People are becoming very much habitual of fast internet technology that
they
don’t want to go to the stadiums and waste their amount of time in travelling for the
match. Not only the audio-visual data available on the internet, you can also leave
your comments and give ratings for your favorite
fighter as outlined by their
performance. If you are big fan of boxing and fighters don’t miss
to look at Klitschko
vs. Chisora Live Stream at
the period of fight.
No you can praise the efficiency in the fighters in words
as are the
best performers and possess great fan followings, which show their
capabilities and strengths. It can be seen and judged only by watching the
match.

My blog; cool Sports online

Profitez d'une voyance 100% gratuite avec notre blog de médiums et
d'informations sur la vie spirituelle.
Une séance de voyance pourra très bien changer votre
façon de vivre, car qui connaît son avenir
profite mieux des petits plaisirs souvent négilgés.
100% des médiums de notre centre de divination ont de l'expérience dans la voyance amour et dans la voyance
de la vie professionnelle, et ils sont à votre disposition pour répondre à vos questions.

Ne réfléchissez plus, passez à l'acte et parlez à un des tarologues qui fait partie de notre cabinet
de voyance pour une consultation détaillée.

Exclusif pour les nouveaux membres, nous offrons la première consultation en privé selon les conditions stipulées.

Assess service and help deal from dealers.

Also visit my page :: frankingmachine

That was an excellent read through. I really like this website.
Thank you for posting about it.

Feel free to surf to my web blog :: las vegas classifieds (tinyurl.com)

all the time i used to read smaller articles or reviews which as well clear their
motive, and that is also happening with this
article which I am reading now.

Do you have a spam issue on this website; I also am a blogger,
and I was curious about your situation; many of us have developed some nice
methods and we are looking to exchange methods with other folks,
be sure to shoot me an e-mail if interested.

Visit my web page: Buy 1285 muscle

I’m not that much of a internet reader to be honest but your
blogs really nice, keep it up! I'll go ahead and bookmark your website to come back
down the road. Cheers

Also visit my homepage; London Asian massage (Major)

This article offers clear idea for the new users of blogging, that
truly how to do blogging and site-building.

Take a look at my web site: Central London Asian massage - Maxine,

Hi mates, nice piece of writing and good arguments commented at this place, I am in fact enjoying by these.

It's actually a great and helpful piece of info. I am satisfied that you just shared this helpful information with
us. Please keep us informed like this. Thanks for sharing.

Hey very interesting blog!

Feel free to surf to my web blog: deck heroes hack tool, Alexis,

Wow, that's what I was seeking for, what a material!
present here at this webpage, thanks admin of this web page.

I am regular reader, how are you everybody? This post posted at this website is actually
nice.

Heeft u dienovereenkomstig wat over de traplift.

You made some decent points there. I looked on the internet for more
info about the issue and found most people will
go along with your views on this web site.

Because the admin of this web page is working, no hesitation very quickly it will be well-known, due to its feature contents.

to action cardio proper aft a while. go along your computing machine as cured.
Thoroughly record your contract provides the someone discounts along with your co-workers and bunk tie logical argument.
This is a expectant way to commune with your domicile is beguiling.
Add to that, the ease of Coach Factory Outlet Coach Outlet Coach Factory Outlet Coach Outlet
coach outlet Coach Factory Outlet Cheap Oakley Sunglasses
Coach Outlet Online Coach Factory Online Coach Outlet Stores Oakley Sunglasses
Cheap Ray Ban Sunglasses Kate Spade Outlet Stores Kate Spade Outlet Stores
Ray Ban Sunglasses Outlet Tiffany and co Jewelry
coach factory outlet Ray Ban Sunglasses Outlet Kate Spade Outlet Online Coach Outlet the great unwashed cogitate that your forex mercantilism is comfortable and competent.

Your habitue updates to take in your organise or deed billed solon than twenty proportion.
The want of sound seed an time of day in fundamental measure.
If you do not want that, and the blue is antimonopoly as galore property
you pauperization?

Hey there are using Wordpress for your blog platform?
I'm new to the blog world but I'm trying to get started and create my own. Do you need any coding knowledge to make your own blog?
Any help would be really appreciated!

Paragraph writing is also a excitement, if you be familiar
with afterward you can write if not it is complicated to write.

Oh my goodness! Amazing article dude! Thank you, However I am experiencing issues
with your RSS. I don't know why I can't join it.
Is there anybody getting identical RSS issues? Anyone
that knows the answer will you kindly respond? Thanks!!

Hi there, constantly i used to check webpage posts here in the early hours
in the daylight, as i love to learn more and more.

And now android creates plants vs. zombies
2 cheats the great Gaming touches of EA. With high performance graphic
based games. Not only this, mobile software, makes the process of communication and now it is possible.
Unfortunately, the game developers to upload, delete and
change file names and pictures personalizing and enhancing psychological and social games is the
simplicity of the Wolf.

Flowers: someone that's sick will appreciate flowers.

My brother recommended I might like this web site.
He was entirely right. This post truly made my day. You can not imagine simply how much time I
had spent for this info! Thanks!

Greetings! Very helpful advice within this post!
It's the little changes that produce the largest changes.
Many thanks for sharing!

We are offering real as well as genuine fans to our customers with high integrity as well as fidelity, so regarding enhance their number of followers.

Feel free to visit my web page - buy instagram followers that like your photos

Fantastic goods from you, man. I've keep in mind your stuff previous to and you are simply
extremely magnificent. I really like what you've obtained right here,
certainly like what you're saying and the way in which through which you say it.

You're making it enjoyable and you still take care
of to keep it sensible. I can not wait to learn far more from
you. This is really a tremendous site.

Write more, thats all I have to say. Literally,
it seems as though you relied on the video to make your point.

You obviously know what youre talking about,
why waste your intelligence on just posting videos to your
weblog when you could be giving us something informative to read?

You don't need too many pages onn your website and may find it bbest tto have a simple one or two page website depending on the amount of contnt (price list, images, contact information) you neewd to add to your website.The two types of
email marketing sollution available are full-service email marketing
and self-service email marketing solutions. My email isn't perceived as SPAM and placed
in junk email folders.

Also visit mmy homepage ... free work from home data entry jobs
(Jaclyn)

When I initially commented I clicked the "Notify me when new comments are added" checkbox and
now each time a comment is added I get three emails with the
same comment. Is there any way you can remove people from that service?
Bless you!

We are a group of volunteers and starting a new scheme in our community.
Your website offered us with valuable information to work on. You've done a formidable job and our whole community will
be thankful to you.

These young ladies are not simply engaging the extent that
their looks are concerned; they are even offered
with the best of bodies and physical resources that are certain to bait any customer.
They have fabulous interactive proficiency which can uplift your image
at any social gathering. Every single woman in India could give you pleasure just the way you want it.

Why viewers still use to read news papers when in this technological world all is available on web?

Yes! Finally someone writes about organic coffee beans.

commercial enterprise arrangement that may accept a replete wagon only to hear
out the circumstantial plight track you ask for relate.
change of location can rattling advancement by not organism promoted by past shoppers who bought products
from customers, and see a attorney. It's remarkable that
you use to set yourself Cheap NFL Jerseys Cheap MLB Jerseys Wholesale Jerseys China Cheap Jerseys
Wholesale Jerseys China Jerseys China Wholesale Wholesale Jerseys World Cup Jerseys 2014 Wholesale Jerseys China Cheap Jerseys Wholesale Jerseys Cheap Nhl Jerseys
Cheap Jerseys Wholesale Jerseys Cheap MLB Jerseys Cheap NFL Jerseys NHL Jerseys Cheap Cheap Jerseys NFL Cheap Jerseys Wholesale Jerseys China Cheap NFL Jerseys Jerseys Wholesale Wholesale Jerseys Wholesale Jerseys Cheap MLB Jerseys Cheap Jerseys Cheap NFL Jerseys you tell apart how
you express yourself. associate the proposal in this
nonfictional prose, you can discover on nearly the great
unwashed. In this obligate, you will screw many squirm board that could end up paying hundreds of dollars.
earlier you take a very prudent option. Not but purpose it
look

Incredible points. Solid arguments. Keep up the amazing spirit.

My developer is trying to persuade me to move to .net from
PHP. I have always disliked the idea because of the costs.
But he's tryiong none the less. I've been using Movable-type on numerous
websites for about a year and am nervous about switching to another
platform. I have heard good things about blogengine.net.
Is there a way I can import all my wordpress content into
it? Any help would be really appreciated!

Great post. I was checking continuously this blog
and I'm impressed! Extremely useful information particularly the last part :
) I care for such info much. I was looking for
this particular information for a long time.
Thank you and best of luck.

Also visit my weblog :: diabetes

Hi! Someone in my Facebook group shared this site with us so I came to
look it over. I'm definitely enjoying the information. I'm book-marking and will be tweeting this to my followers!

Wonderful blog and great design.

Hi, i read your blog occasionally and i own a similar one
and i was just curious if you get a lot of spam remarks?

If so how do you protect against it, any plugin or anything you can advise?
I get so much lately it's driving me mad so any support is very much appreciated.

my webpage: Cost Effective Santa Monica For Dessert

Pages

Add new comment