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

[p]The Author of this article is an expert on the latest trends pertaining to sunglasses . He has written many informative articles on various sunglass brands & products such as Fake oakleys, Replica Oakleys and Fake Oakley [url=http://www.oakleyprescriptionsunglassessale.com]oakley prescription sunglasses sale
[/url] sunglasses . The Oval experience - with this particular type of encounter form, you can attempt on totally any type of Oakley sunglasses and be able to pull it off . A principal solution that will provide a person both of these exceptional possibilities is available with the investment into Oakley prescription glasses Boomstand . [url=http://www.oakleyprescriptionsunglassessale.com]oakley sunglasses sale[/url] Nz . They not only protect the eyes from the harmful UV rays, but also make the wearer look kind of stylish, cool and mysterious . Some people have no trouble getting fake Oakleys or Foakleys as [url=http://www.oakleyprescriptionsunglassessale.com]oakley polarized sunglasses sale[/url] they are termed just so they can preserve some green . You'll need a beautiful ladies Oakley sunglasses

In the actual morden society, when you are out, you will require a beautiful lady Oakley sunglasses, Which means that you can easily wait the greater expensive models, however, you may regret it when you are done checking away the store or even online . Optical technologies is exclusively utilised in oakley outlet to give a superior high quality of vision.[/p][p]Mens Oakley Sunglasses - Experience the Genuine Really worth

Oakley is popular globally for a collection of products like [url=http://www.oakleyprescriptionsunglassessale.com]oakley polarized sunglasses[/url] footwear, watches, backpacks and sporting shirts, but they are very renowned and renowned for their desirable men's shades . Evening Bags - A Short History in Time . Related Articles - fake oakleys, foakleys, fake oakley sunglasses, cheap oakley sunglasses,

Email this Article to a Friend!

Receive Articles like this one direct to your email box!Subscribe for free today! . com

Sunglasses are very popular fashion status symbols . Verify out the Oakley polarized sunglasses, I feel you could be pleasantly impressed . Inexpensive Oakley Sunglasses

You prefer to travel? Do you need to sell things? If that's the case, why not close to sunglasses wholesale product sales, in fact, promote their very own travel . Cheap Oakley [url=http://www.oakleyprescriptionsunglassessale.com]oakley prescription sunglasses[/url] Sunglassesmade headlines recently with its donation of 35 pairs of "Radar" sunglasses to the Chilean miners to protect their eyes upon their escape from their cave after 66 days underground . It is my private impression but I just don't see how you can help save money buying fake Oakleys time and time yet again as opposed to acquiring genuine ones an individual time.[/p]

As the admin of this web page is working, no doubt very soon it
will be well-known, due to its quality contents.

Nice pos&X74;. I wa&X73; checkіng contin&X75;ously &X74;his &X62;log and ӏ am impressed!
Extremely hе&X6C;p&X66;ul info part&X69;culaгly&X74;he last pаrt :) I
care for such info a lot. I was seekі&X6e;g &X74;hіs pаrticular inf&X6f; for a νery long tіmе.

Thank you аn&X64; best of luck.

Feel frеe to surf &X74;&X6f; mу web b&X6c;og :
: robert sigg

Fascіnating blog! Is yoսr tɦеme custom made or did you download it
from somewhere? A themе like yours with a few simple tweeks would really
make my blog stand out. Please let me know where yoս got your theme.
Cheers

How cool is the fact that? The usage of Blue
ink is now publicized to be used in advanced franking equipments
as a better option from the Red printer ink. Efficiency Franking machines are quieter and
more successful than ever. In general, frank mail systems are split up into four categories:
They'd much prefer to acquire personalised post, instead of boring blank snail mail.
When your firm uses Royal Postal mail VAT liable products, then the
answer is indeed. And likewise, franked mail is 30% cheaper than stamped snail mail.

My web-site :: franking machine

On the other hand, productivity may be improved from the easy introduction of a franking device whole with integrated electronic scale.

Also visit my site: franking machine

Replaceable energy resources like solar-panel creates complete carbon-free electricity ready to be used anytime.

my blog post :: solar panels

It's going to be end of mine day, however before finish I
am reading this impressive post tto increase my experience.

Visit my weblog; reviews of Magic submitter

Hi! I've been reading your web site for a while now and finally got the bravery to go ahead and give
you a shout out from Houston Tx! Just wanted to mention keep up the good job!

Some of the rapid benefits you could expect from a productive Solar PV are numerous.

My homepage; solar panels

Hey! Do you know if they make any plugins to help with
SEO? I'm trying to get my blog to rank for some targeted keywords but I'm
not seeing very good gains. If you know of any please share.
Many thanks!

Apart from the care cost, you also have to buy consumables including
franking ink and labels.

My weblog; postagemachines

I was recommended this web site by my cousin.
I'm not sure whether this post is written by him as no one else know such detailed about my problem.

You're incredible! Thanks!

Have a look at my webpage :: double glazing

Optez pour une consultation de voyance gratuite grâce à ce site web de tarologie et d'astrologie.

Une séance de voyance va probablement faciliter votre façon de vivre, car qui connaît son avenir saisit mieux les petits plaisirs de tous
les jours.
Nos voyants de confiance ont de l'expérience dans la voyance amour et dans
la prédiction du travail, et ils se feront un plaisir de vous
donner des conseils précieux.
Si vous êtes intéressé, passez à l'acte et
entrez en communication avec un des tarologues de l’équipe de notre cabinet
d'astrologie et laissez-vous prédire votre futur.

Vu que nous voulons que votre bien, nous offrons le premier appel
avec une voyante durant 10 minutes.

Optez pour une séance de voyance sans payer avec ce blog de voyants et d'informations
sur la vie spirituelle.
Une discussion avec une voyante pourra très bien améliorer votre façon de vivre,
car qui a connaissance de son avenir saisit mieux les petits plaisirs au quotidien.

Les médiums présentés sur notre blog sont spécialisés dans la voyance amoureuse et dans la
prédiction de la vie professionnelle, et ils vous donneront des conseils précieux.

Si vous êtes intéressé, réagissez maintenant et
contactez un des médiums de l’équipe de notre centre de divination pour une prédiction détaillée.

Vu que nous sommes persuadé du sérieux de nos voyants, nous offrons le premier appel avec une voyante selon les conditions
stipulées.

. That is how cool? Apart from the maintenance expense, you must also purchase consumables including franking ink and labels.
The middle of/ Great Volume that will process 30 to 500
mails a day 4. This is a wonderful advantage as
it offers more quickly processing preserving much of
your valuable time. Inefficiency wastes money and time and try to means knock-on costs.
A first school stamp costs 39p using the second type version
presently standing at 30p. If you are running a small business
a home franking machine should do the job you require.

Holiday on your neighbourhood firm programs store or lookup the
on-line world.

Check out my homepage :: frankingmachine

Please let me know if you're looking for a writer
for your weblog. You have some really good articles
and I feel I would be a good asset. If you ever want to take some of the
load off, I'd love to write some content for your blog in exchange for a link back to mine.
Please shoot me an email if interested. Thank you!

My partner аnd I absolutely love your blog anԁ find the majority of your poѕt's to be just what I'm lоoking for.
can you οffer guest wrіters to write сontent availаble for you?
I wouldn't mind producing a post or elaborating on most of the subjects you write related to here. Again, awesome website!

Really when someone doesn't be aware of after that its up to other people that they will assist, so here it occurs.

Employing a franking device indicates you be eligible for many reductions, no matter what quantities of post you
use.

Here is my homepage; frankingmachine

Right here in the U.k. we currently have Four claiming franker (as us
Brits want to contact them) companies.

Here is my page: franking machine

If some one needs to be updated with hottest technologies
therefore he must be pay a quick visit this site and be
up to date everyday.

Nice weblog here! Also your web site lots up fast!
What web host are you using? Can I am getting your affiliate
hyperlink for your host? I want my site loaded up as fast as yours lol

Profitez d'une consultation de voyance gratuite avec ce blog de voyants et de tout ce qui touche à la
voyance.
Un entretien avec un médium pourra très bien faciliter votre
vie, vu que toute personne qui découvre son avenir reconnait mieux les petits plaisirs au quotidien.

Les médiums expérimentés ont de l'expérience dans la voyance de la vie amoureuse et dans la voyance professionnelle, et ils se
feront un plaisir de répondre à vos questions.
Ne vous posez plus de questions, passez à l'acte et contactez un des membres de notre équipe de voyance et demandez une prédiction personelle.

Afin de vous mettre en confiance et prouver le sérieux de nos voyants, nous offrons la première communication en privé avec un médium selon les conditions stipulées.

Solar PV is really one of the best financial assets around at the moment.

Here is my web site ... solarpanels

My programmer is trying to convince 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 a variety of websites
for about a year and am concerned about switching to another platform.
I have heard fantastic things about blogengine.net. Is there a way I can transfer all my wordpress content into it?
Any help would be greatly appreciated!

Outstanding quest there. What happened after? Thanks!

Look at my web site ... how to share large video files

Our approved contractors will proceed through most of the options, aiming the costs as well
as the income from your Feed in Tariff.

Have a look at my blog post - solarpanels

If some one wishes to be updated with most up-to-date technologies therefore he must be go to see this site and be up to date
all the time.

The first thing to understand about Solar PV Sections is
that they don't need a hot shining day to produce electricity.

My blog: solar panels

Cliquez ici pour recevoir une consultation de voyance 100% gratuite grâce à ce
site web de voyants et d'informations sur l'astrologie.

Une communication avec un voyant va probablement changer votre vie, parce que ce celui qui découvre sa vie future saura mieux profiter des chances de tous
les jours.
Tous nos voyants présentés sur ce annuaire ont de l'expérience dans la prédiction
de la vie amoureuse et dans la divination de la
vie professionnelle, et ils se feront un plaisir de répondre aux questions.

Ne vous posez plus de questions, faites le pas et contactez un des membres de
l’équipe de notre centre d'astrologie et laissez-vous
prédire votre futur.
Exclusif pour les nouveaux membres, nous offrons
la première consultation personnelle de votre choix.

. That is how cool? The newest generation of franking machines
are a variety of models to suit any business.

Consider answering these queries about your mailing volumes.
"Penney Red" was a per paid for franking: Do I need franking machine for my
business? You might not need to frank 10,000 letters per hour but your company can still advantage by having one of the low volume level Franking Machines.

You'll also have to consider every note or bundle separately after which check out
the related postal cost.

Alongside that the typical family Solar PV method
is all about 20.

Look into my web site solarpanels

Hello there! Quick question that's entirely off topic.

Do you know how to make your site mobile friendly? My website looks weird when viewing from my iphone
4. I'm trying to find a template or plugin that might be able
to correct this problem. If you have any suggestions, please share.
With thanks!

You are amongst friends or at least within an agreeable alliance of those who visit your site looking
for both informative content but in a casual setting so make it for them.
Whether you're just how to get started or merely looking for
a few pointers to improve your website, the wealth of information
available on this subject might be overwhelming.

Way cool! Some very valid points! I appreciate
you writing this article and the rest of the site is really good.

Still, the development of Internet connectivity
does create new challenges for domestic leaders who have proved greater than capable of controlling older
forms of communication. Firefox is really a powerful browser, is free and open source descended through the mozilla.

It's awesome in favor of me to have a site,
which is good in favor of my experience. thanks
admin

What's up Dear, are you in fact visiting this web page on a regular basis, if so
then you will definitely obtain nice knowledge.

Pages

Add new comment