Surf - est le temps de chargement dans l'autre main - est le grand probl
- Demo
- Agrandir
- Recharger
- New window
G�n�rez vos vid�os d'entreprise par l'IA avec la voix ou simplement du texte
Votre premi�re application vid�o AI GRATUITE ! Automatisez votre premi�re vid�o AI. Cr�ez votre vid�o professionnelle en 5 minutes gr�ce � l'IA. Aucun �quipement ni comp�tence en montage vid�o requis. Production vid�o sans effort pour les sp�cialistes du marketing de contenu.
Method 2: Preloading with JavaScript Only
As effective as the previous method happens to be, I generally find it to be too tedious and time-consuming to actually implement. Instead, I generally prefer to preload images using a straight-up slice of JavaScript. Here are a couple of JavaScript-only preloading methods that work beautifully in virtually every modern browser..
JavaScript Method #1
Unobtrusive, gracefully degrading, and easy to implement, simply edit/add the image paths/names as needed - no other editing required:
This method is especially convenient for preloading large numbers of images. On one of my gallery sites, I use this technique to preload almost 50 images. By including this script on the login page as well as internal money pages, most of the gallery images are preloaded by the time the user enters their login credentials. Nice.
JavaScript Method #2
Here's another similar method that uses unobtrusive JavaScript to preload any number of images. Simply include the following script into any of your web pages and edit according to the proceeding instructions:
As you can see, each preloaded image requires a variable definition, "img1
=
new
Image();
", as well as a source declaration, "img3.src
=
"../path/to/image-003.gif";
".
By replicating the pattern, you can preload as many images as
necessary. Hopefully this is clear - if not, please leave a comment and
someone will try to help you out.
We can even improve this method a bit by delaying preloading until after the page loads. To do this, we simply wrap the script in a function and use addLoadEvent()
to make it work:
Ahhh, the joys of JavaScript!
Method 3: Preloading with Ajax
As if all of that weren't cool enough, here is a way to preload images using Of Geeks and letters, and uses the DOM to preload not only images, but CSS, JavaScript, and just about anything else. The main benefit of using Ajax over straight JavaScript is that JavaScript and CSS files can be preloaded without their contents affecting the current page. For images this is not really an issue, but the method is clean and effective nonetheless.
As is, this code will preload three files: "preload.js
", "preload.css
", and "preload.png
". A timeout of 1000ms
is also set to prevent the script from hanging and causing issues with normal page functionality.
To wrap things up, let's look at how this preloading session would look written in plain JavaScript:
Here we are preloading our three files upon page load by creating three elements via the DOM. As mentioned in the original article, this method is inferior to the Ajax method in cases where the preloaded file contents should not be applied to the loading page.
Know some triks?
I love these preloading tricks so much, I could just squeeze something. If you know of any good preloading tricks, including any improvements to the techniques shared here, kick start my heart with your wise words of preloading wisdom ;)
- Sent (0)
- Nouveau