google+javascriptbanktwitter@js_bankfacebook@jsbankrss@jsbank






Chargement externe CSS et JavaScript fichiers plus rapidement avec PHP mod_rewrite


�tiquette: la vitesse de chargement, Fichier CSS externe, mode PHP, mod_rewrite, Web Developer, Astuce d

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.
Essayez iPage GRATUIT premi�re ann�e MOMENT

The landscape of the internet has changed a great deal over the years. Websites are no longer static and lifeless, they have become dynamic and interactive. A consequence of this is that the size of modern websites has increased significantly. This poses a couple of important issues:

  1. It takes more time for webpages to be downloaded by client browsers.
  2. Average website bandwidth usage has increased.

Most internet surfers won't wait 30 seconds for a page to load in its entirety, they'll simply move on to something else. Also, if you own or manage an even moderately busy website you will know just how much bandwidth is worth. It is a precious commodity that can increase the figures on your monthly hosting bill. As a result of this, a lot of emphasis is now being placed on website optimization.

Yahoo has published a set of rules which outlines some of the methods that can be employed to make your website as lean and fast as possible. One of the methods suggested is to compress and minify external CSS and JavaScript files. Some PHP frameworks employ some form of optimization of these files and if you have control over your server you can always install mod_gzip which would handle compression of these files. If you are not using a PHP framework or you use a shared hosting plan (most of which won't allow you to use mod_gzip because it can be a CPU hog) then read on.

First off, we will create a .htaccess file in which we will put our rewrite rules:

IndexIgnore *

<IfModule mod_rewrite.c>
	RewriteEngine on
	RewriteRule ^(.*\.((js)|(css)))$ optimizer.php?file=$1
</IfModule>

Place a copy of this file in your /js and your /css folders. The first line really has nothing to with our optimization, all it does is it prevents listing of the contents of the directory when someone navigates to http://www.yourdomain.com/js or http://www.yourdomain.com/css. Not necessary but good practice. The next few lines redirects incoming requests to the file optimizer.php if the file extension is .js or .css and passes the filename to it as a query string. Next, we'll create a file called optimizer.php:

<?php
if(!isset($_GET['file'])) die('Invalid parameter!');

$file = file_get_contents($_GET['file']);
$file = preg_replace("/((?:\/\*(?:[^*]|(?:\*+[^*\/]))*\*+\/)|(?:\/\/.*))/", "", $file);

header("Expires: Fri, 21 Dec 2012 00:00:00 GMT");
header("Content-type: application/x-javascript");
ob_start("ob_gzhandler");

echo $file;
ob_flush();
flush();
?>

This file should also be placed in both the /css and /js folders. What this script does is it grabs the filename from the $_GET array, reads the contents of the file into a variable, strips the file of all comments, sends content type and expires headers to the browser, compresses the contents of the variable (via output buffering) and sends the optimized CSS or JavaScript back to the browser. Simple and straightforward.

This method is a simple way to optimize your external .js and .css files when you don't have access to better(?) methods. The only issue I have noted so far with this method is that it will mess up the minified version of the jQuery library which really isn't an issue since its already minified. If you are using the minified version of jQuery on your website simply use this code in your optimize.php file instead:

<?php
if(!isset($_GET['file'])) die('Invalid parameter!');

$file = file_get_contents($_GET['file']);
$jqueryFile = 'name_of_your-jquery_file';

if($file!=$jqueryFile) $file = preg_replace("/((?:\/\*(?:[^*]|(?:\*+[^*\/]))*\*+\/)|(?:\/\/.*))/", "", $file);

header("Expires: Fri, 21 Dec 2012 00:00:00 GMT");
header("Content-type: application/x-javascript");
ob_start("ob_gzhandler");

echo $file;
ob_flush();
flush();
?>

Now go optimize your stylesheets and JavaScripts and make your users happier!

Footnote #1: This implementation will obviously only work on an apache server as a .htaccess file is used.

Footnote #2: The code used in this post is simply a proof of concept. Little or no attention was paid to security. In an actual implementation of this technique you would need to ensure that this script is as secure as possible.

AIVideo-App.com
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

Artificial General Intelligence
Ai and higher level Artificial General Intelligence (AGI)

Artificial General Intelligence
Ai and higher level Artificial General Intelligence (AGI)

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

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

Powerful AI Presentation PPT Maker for FREE
Build an impressive presentation with our free online AI presentation app

Your next top AI Assistant
Claude AI, developed by Anthropic

Your next top AI Assistant
Claude AI, developed by Anthropic

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 $

JavaScript par jour


Google Safe Browsing McAfee SiteAdvisor Norton SafeWeb Dr.Web