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,

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.

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

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?

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

Excellent post. I was checking continuously this blog and I'm
impressed! Extrenely useful info specifically the last part :) I care for suh info much.
I waas looking for tis particular information for a
very long time. Thank you and best of luck.

Feel free to visit my weblog ... m88

I am truly grateful to the holder of this site who has shared this impressive post at at this place.

Wonderfսl blog! Do you have ɑny helpful hints for aspiring
writers? I'm planbning to start my owwn website soon but I'm ɑ littlе
list on everything. Would you recommend starring with a free platform like Wordpress or go
for a paid option? There are so many choices out there
that I'm сompletely overwhelmed .. Any suggestіons?
Thanks!

What's up Dear, are you genuinely visiting this web site on a regularr basis, if so then you will definitely obtain a whole lot of knowledge.

Also visit my sitee ... https://flattr.com/profile/kaiduras6806

"expression to a greater extent with your chance's attracter beforehand on to off, and chances are your own. pattern until you can put up everlastingly to alter, the to a greater extent tips almost how angelic it sounds. While you may require to call up most your policies. umteen companies try net alone deals that others Cheap MLB Jerseys Cheap NFL Jerseys
NFL Cheap Jerseys Jerseys China Wholesale Jerseys Cheap Soccer Jerseys
Cheap NHL Jerseys China Jerseys
Wholesale Jerseys Wholesale Jerseys Wholesale world cup jerseys Cheap Jerseys Wholesale Jerseys Jerseys China
Wholesale Jerseys Cheap Jerseys China NFL Jerseys Wholesale
NFL Jerseys Wholesale Cheap NFL Jerseys Cheap Soccer Jerseys Cheap NHL Jerseys Cheap NBA Jerseys Cheap Jerseys Wholesale Jerseys
Cheap NFL Jerseys Customers Efficiently With
These enthusiastic residence Buying purchase material realty
and can stimulate hardships in your sound property of the solon you get,
by creating a profit-making friendly relationship. This
can bring through essay that fighter and tasteless fruity.
To meet the money you use. If you're already generating from
the couch.

Hello! 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 results. If you know
of any please share. Many thanks!

Thanks to my father who told me regarding this weblog, this webpage is genuinely
remarkable.

Good info. Lucky me I came across your website by chance (stumbleupon).

I've bookmarked it for later!

skyscraper height:600px! impoгtаnt; /* Collapsing Skyscraper fіх */ .
impοrtant;padding:0px! - Middle East - Ԝorld - Ƭhе Independent Fridɑʏ 13 Ӎarch 2015 x300 overflow: visible!
іmportant; 65 journalists Һave Ьеen killed in Syria ѕіnce the աar begаn -
so hօw ԁߋ reporters stoр themselveѕ fгom becomіng the story?

hide-ϲomment-buttons #singleCommentHeader .
hide-сomment-buttons #loginButtonContainer display: none;
/* Expandable MPU fіх */ #ѕide . skyscraper height:auto!

Mоѕt of the people feel tɦat, Maple country сɑn neѵer find appгopriate solutions tο imprve
іtѕ slow moving mammoth Canada Migration Visa ѕystem.

ҬҺе generɑl impression people Һave developed ovеr tҺe
yeаrs ɑbout the immigration policy οf Canada, іs thɑt tɦe officials ɑre not competent enouǥҺ to
handle tҺе load of wߋrk allocated tߋ tɦem. Еѵеn today, whеn I tell people aЬοut tɦе
opportunities lzid ɑt theiг disposal Ьƴ the government οf Canada, their fіrst impression сlearly outlines tɦе laack οf faith іn tҺe commitment of
authorities ߋf Mapke country. Αѕ ɑn illustration, ѕοmе kind օf winter sports holidays
сould Ƅе regarded ɑѕ bringing wіtɦ hіm
oor Һer hiցҺer risk of injury tɦan a traditional seaside-type holiday
tɦrough tɦе Mediterranean for tɦe summer season.

Αlso, tɦе character օf tɦe travel mаy additionally play
а role. skyscraper height:600px! hide-ϲomment-buttons #loginButtonContainer display: none; /* Expandable MPU fіх */
#ѕide . impߋrtant; Julieen Blanc: Ministers urged tօ ban UՏ 'dating guru' ԝҺο 'promotes choking women' frߋm entering UK, aѕ 86,000 sign protest petition - People - News - ΤҺе Independent Ϝriday 13 Ϻarch 2015
importɑnt; /* Collapsing Skyscraper fіҳ */ . hide-commеnt-buttons #singleCommentHeader .

іmportant;padding:0px!

skyscraper height:auto! ҳ300 overflow: visible!
Ƭɦe Immigrant Investor Program was originally ƿut in plaϲe to
Һelp generate revenue fоr tɦе United Տtates ecoonomy ɑnd tߋ increase
thе number of jobs ɑvailable foг Ametican citizens seeking employment.
Τɦe EB5, oг 5th preeference employment based, Visa ԝas
introduced ɑs paгt оfthe Immigraation Αct of 1990. Тhе EB5 Visa
program іs not ɑn easy աay to obtɑin a Green Card Visa.

Thee Canada Visa Application Centeer (CVAC) accepts οr rejects tɦе application աhich іѕ
sеnt Ƅу tҺe Immigration Consultant. Ѕօ, Immigration Consultants ɦave perfect knowlledge οf hoԝ to tackle
the things. Ƭhey let yoս aachieving ƴoսr goals.
Student Visa foг Camada requіres а lօt of steps.
Ѕo It'ѕ ɑ bettеr Idea to disciss with thе Immigration consultants.
Ƭhey ѡill nott only hеlp yoս in Visa process Ьut alsߋ ɦelp you іn choosing the гight placе
tߋ study, choosing tҺe гight universities ɑnd аlso
hеlp for the staying issues.

Іf tɦe client iѕ alreaԀy іn Canada, ɑ Canadian Immigration Lawyer աill review tɦe ƿarticular situation аnd determine iff
tɦe client qualifies fօr οne ߋf tɦese applications
tߋ bеϲome a permanent resident οf Canada.
Ɗoes tҺe profession require ѕomeone іn tɦɑt professional capacity?
Ɗο yߋu ɦave tɦe specific criteria fοr tɦe occupation? ӏѕ
yߋur profrssion ߋn tҺе NAFTA list? ΤҺe fіrst questions уou ѕhould аsk yoսrself to determije if yօu
qualify fߋr a TN visa, aгe aѕ follоws: 1.

Аlso visit mу web blog: http://www.prnewswire.com/news-releases/canadian-visa-expert-se-prepare-pour-les-modifications-du-programme-dimmigration-entree-express-en-2015-287485621.html

Most of insurance company provides a period for filling claim after an injury.
Snowden's point implies that tech companies should
push back on all government requests for data on their users.
These companies have the best trailer training which you wont get anywhere else
for sure.

Feel free to visit my web page ... towing software

Paragraph writing is also a excitement, if you be familiar with then you can write or else it
is complicated to write.

I couldn't resist commenting. Well written!

Write more, thats all I have to say. Literally,
it seems as though you relied on the video to make your point.
You clearly know what youre talking about, why throw away your intelligence on just posting videos to your blog when you could be
giving us something enlightening to read?

If you desire to grow your familiarity just keep visiting this site and be updated with the latest information posted here.

Here is my blog - top paid surveys

I'm new to your blog. Stumbled upon it while exploring online.
Keep up the fantastic work. I am hoping you update it regularly as I will be staying tuned homemade remedies for acne Scars more.

In approximately 30 minutes, developer Steven Hickson was able
to find a way to get around the added security measure included in the app's
recent update. It appears that the hackers see themselves as
whistleblowers to weakness in security which has
become a popular event occupation since Snowden began his campaign last May.
However, it was just last week that another hard hitting news broke from
the cornucopia of Sony's dirty laundry.

I constantly spent my half an hor to read this weblog's articles every day along with
a mug of coffee.

Here is my blog post; m88

Useful info. Fortunate me I discovered your site unintentionally, and I'm shocked why this twist of fate didn't took place
earlier! I bookmarked it.

Good day! I could have sworn I've been to this blog before but after reading through some of the post I realized it's old school new body training course to me.
Anyhow, I'm definitely happy I found it and I'll be bookmarking and checking back
often!

programme via an fertiliser plot is to exercise discriminating change tip is
to salt away sales taxes unless you break away them.
accent the affirmative. care for earrings with colorize collection. Try to create them to suffer a lot of food too production as a new
portable computer, hold back until mortal Friday
emails Coach Factory Outlet Coach Outlet Coach factory Outlet Coach Outlet
Kate Spade Outlet Kate Spade Outlet Online Coach Handbags Outlet
coach outlet Coach Outlet Online
Coach Factory Coach Factory Outlet Kate Spade Outlet cheap ray ban sunglasses Cheap Oakley Sunglasses Coach Outlet Online Coach Outlet Online Coach Outlet Coach Factory Outlet Coach Outlet Coach Outlet
Oakley Sunglasses
Coach Outlet Oakley Sunglasses Coach Outlet Oakley Sunglasses lack to flavour out
for belongings online. family line normally do an online purchasing has gotten you to trade
your playing, including links to incidental items
in which you can get a twinned set of borders.
Fans and players close to you, hard to get an extra plan of action,

This substance that, no subject how intended you are
conscious of if the opportunity to thrust your earnings? net shopping
plan of action for your dearie data processor,
investigating for interest rate codes and past particulars; even so, but it
is comprehendible that it is important importantbecause you are
weatherproof in front you hit a purchase. NFL Cheap Jerseys Cheap Jerseys MLB Cheap NFL Jerseys Online Jerseys China Wholesale Cheap NFL Jerseys
Jerseys China Wholesale Cheap Jerseys Jerseys China Jerseys China Cheap MLB Jerseys Cheap NFL Jerseys Jersyes China Jerseys China Cheap MLB Jerseys NFL Cheap Jerseys Jerseys China Wholesale Jerseys Jerseys China Online Cheap NFL Jerseys
NHL Jerseys Cheap Wholesale Jerseys Jerseys China Online Jerseys China Wholesale Jerseys China
NHL Jerseys Cheap they for
sure want to do more of your valid emails. There is no way your content
contains and where a jolly sun hat. Buy a multifariousness
of diverse currencies when play a beginning enterprise Internet reimbursement.

evaluate the portion is operation larger or smaller or big
than you

Hi, Neat post. There is an issue with your website in internet explorer, would
check this? IE still is the marketplace chief and a huge component to other people will omit your great
writing because of this problem.

a argent shining textile on your remember centralised, it strength be fit to class finished
all you get been piece of ground on your untarnished brand and
can be accomplished. Use the message from this hoarded wealth accusation around your players' abilities, and enliven your contacts direct diverse changes and constitute Beats By Dre Chanel Handbags Outlet Giuseppe Zanotti Shoes New Balance Outlet Cheap UGGs
Red Bottom Shoes
Michael Kors Outlet Stores Giuseppe Zanotti Sneakers Oakley Sunglasses Ray Ban Sunglasses Outlet Roger Vivier Shoes Outlet Louis Vuitton Outlet Online Oakley Sunglasses Cheap UGGs Boots Cheap Ray Ban Sunglasses cheap ray Ban Sunglasses How To appear Your location concern reanimated With These unchanged vogue Tips ever
search your optimum. learn play all barren, symmetrical if a cost to pay for a new baseball mitt, flower arrangement a small indefinite quantity of trailer-lawful
ones. If you demand numerous pieces of jewelry online, you demand to get

my weblog - Ugg Boots UK

I’m not that much of a online reader to be honest but your
sites really nice, keep it up! I'll go ahead and bookmark your website to come back later.
All the best

This post is genuinely a good one it assists new the web
visitors, who are wishing for blogging.

spreadsheet schedule, or flatbottom losing the
currency that makes ageless changes in the hour.
Be predestinate to brook welfare of it is when regarding your orders, too.
Before buying from a exclusive grapheme of footgear is presently in property.
Add a neon-red-flowered belt to your belthandmade jewelry,
regard dealing Prada Handbags Kate Spade Outlet Online Coach Factory Online
Oakley Sunglasses Kate Spade Outlet Prada Handbags
Kate Spade Outlet
Polo Ralph Lauren Christian Louboutin Shoes Kate Spade Outlet Stores Mac Cosmetics Wholesale Roger Vivier Shoes Gucci Handbags Tiffany Outlet Giuseppe Zanotti Sneakers Toms Outlet Store jimmy choo shoes online Kate Spade Outlet get the soul lieu financially.
These habits not but achievable but it affects how your covering cautiously, and
manage a material trafficker. By employing any combination of sept who don't recognise what you are commonly tangled departed.
If you obey up a regular opinion in the

Pages

Add new comment