Plusieurs jours auparavant, dans les didacticiels de l'article JavaScript sur l'optimisation de la performance web, ACC @ nk a ?galement mentionn? l'importance de la compression des fichiers JavaScript Vous pouvez toujours les lire ? nouveau:
Performances des compresseurs JavaScript
? Conseils sur les performances JavaScript
? Speed Up de performances JavaScript avec SharePoint Minifier
? Compresser automatiquement les fichiers JavaScript sur Apache
- Demo
- Agrandir
- Recharger
- New window
Gratuit iPage h�bergement Web pour la premi�re ann�e MOMENT
Si vous �tes toujours � la recherche d'un fournisseur d'h�bergement Web fiable avec des tarifs abordables, pourquoi vous ne prenez pas un peu de temps pour essayer iPage, seulement avec $1.89/month, inclus $500+ Cr�dits suppl�mentaires gratuites pour le paiement de 24 mois ($45)?
Plus de 1.000.000 de clients + existisng peuvent pas avoir tort, vraiment vous n'�tes pas aussi! Plus important encore, lorsque vous enregistrez l'h�bergement web � iPage gr�ce � notre lien, nous allons �tre heureux de renvoyer un plein remboursement. C'est g�nial! Vous devriez essayer iPage h�bergement web GRATUITEMENT maintenant! Et contactez-nous pour tout ce que vous devez savoir sur iPage.
One of the best practices to increase our site performance is to reduce the JavaScript file size and saving time for downloading it. On 5th of November 2009, Google has announced the release of Google Closure Compiler. So, what is that all about? In a nutshell, Closure Compiler is a tool that is used to rewrite our JS code to make it faster and more compact. In this post, I will go through with you, how can we build and compile our JS code with this optimizer on Windows platform.
To run the compiler on our machine, we need Java 6 or higher to be installed. If you have already had Java 6 or higher installed, just grab a Closure Compiler executable file. There are three ways for getting it:
1) The pre-built version - it can be found and downloaded at: http://code.google.com/p/closure-compiler/downloads/list
2) Check out the source and build it with Apache Ant
3) Check out the source and build it with Eclipse.
However, I will not explain into details for 2) and 3). I will use
the pre-built version for compiling JS file instead. So, before we run
the closure compiler, we need the executable file first. Just download
the latest copy from this link.
Once we have downloaded the compressed folder, extract all files and
locate it in an empty folder, say 'work' folder. We should be able to
see 3 files inside, as follows:
As what you have seen, the compiler is in executable jar file format. And, the 'README' is the guide of running this optimizer tool. Running the compiler is pretty straight-forward, just follow these steps will do:
1) Say, I would like to compress 'facebox' jQuery plugin which is
not compressed and the original file size is 10KB. What I want is to
reduce its file size so that my site is not taking much time for first
downloading the JS file. So, what I need to do is, copy the original JS
file to the 'work' folder, like so:
As you can see, the original file size is 10KB in the folder.
2) Next, open the Windows' command line, and change the directory to the 'work' folder, as the screenshot shown at below:
We are now at the 'work' folder. To execute the compiler, type in the following command:
3) Once we pressed 'Enter', this starts the compiler in interactive
mode. The next thing we need to do is to type in 'var x = 17 + 25;' ,
just as follows:
4) Next, hit the 'Enter' key once we are done, and then hit the
'Ctrl-Z' keys and once again, hit the 'Enter' just after the 'Ctrl-Z'.
The compiler will respond to us as 'var x=42;', as shown in this
following srceenshot:
5) OK now, basically we are able to rewrite and compile our JS file
at this stage. The optimizer tool has many options to read the input
file and checking our code and so on. Such as, how to compile multiple
JS files, etc. However, we will focus on one file in this tutorial. To
compress and reduce 'facebox' plugin file, type in and run the
following command:
To make it clearer, this command should be something like this:
java -jar compiler.jar --js facebox.js --js_output_file facebox-compiled.js
Please take note that, you are free to name the output of your JS file. In this case, I named it as 'facebox-compiled.js'.
6) Open the 'work' folder again after the command is executed, you
should be able to see an additional file (facebox-compiled.js) inside
the folder:
If you have noticed, the original file size has been reduced from 10KB to 5KB, which is 50% of reduction with the file size! To see the code, open the compressed file with your preferred text-editor, you should be able to see the code has been optimized and rewritten as well as obfuscated. This will prevent visitors to read your JS code straight from their browser's 'View Source' option. Below is the example how does the code look like:
To learn more about Closure Compiler, please visit: http://code.google.com/closure/compiler/docs/gettingstarted_app.html. Hope you enjoyed it.
Conclusion:
Google Closure Compiler is a powerful optimizer tool to analyze and
rewritten our JS code. It will greatly reduce our file size as well. JS
file size should always be concerned for the sake of the site
performance.
- Sent (0)
- Nouveau
Générez vos vidéos d'entreprise par l'IA avec la voix ou simplement du texte
chatGPTaz.com
Parlez à ChatGPT dans votre langue maternelle
AppAIVidéo
Votre première application vidéo AI GRATUITE
Deepfake Video
Deepfake AI Video Maker
Deepfake
Deepfake AI Video Maker
AI Deep Fake
Deepfake AI Video Maker
AIvidio
AI Video Mobile Solutions
AIvideos
AI Video Platform & Solutions
AIvedio
AI Video App Maker
Faceswap AI en ligne
Échangez des visages, des vidéos, des photos et des GIF instantanément avec de puissants outils d'IA - Faceswap AI Online GRATUIT
Faceswap AI en ligne
Échangez des visages, des vidéos, des photos et des GIF instantanément avec de puissants outils d'IA - Faceswap AI Online GRATUIT
Temu gratuit 500 $ pour les nouveaux utilisateurs
Claim Free Temu $500 Credit via Affiliate & Influencer Program
Crédits publicitaires TikTok gratuits
Maîtrisez les publicités TikTok pour le marketing de votre entreprise
Dall-E-OpenAI.com
Générez automatiquement des images créatives avec l'IA
chatGPT4.win
Parlez à ChatGPT dans votre langue maternelle
Premier produit d'intelligence artificielle d'Elon Musk - Grok/UN.com
Parlez au chatbot Grok AI dans votre langue
Outily.win
Centre d'outils ouvert et gratuit, utilisable par tous et pour tous, avec des centaines d'outils
GateIO.gomymobi.com
Airdrops gratuits à réclamer et à partager jusqu'à 150 000 $ par projet
iPhoneKer.com
Économisez jusqu'à 630 $ à l'achat d'un nouvel iPhone 16
Acheter le robot Tesla Optimus
Commandez votre robot Tesla Bot : Optimus Gen 2 dès aujourd'hui pour moins de 20 000 $