How to Cache External Javascript
When a web browser loads a new web site, it downloads files to a local cache. The web browser can then quickly access files from the local cache instead of redownloading the same file twice. If you have your own web site, you can control how web browsers cache files by creating a file named “.htaccess” in the root directory of your site. This file can define caching behavior. For example, you can force browsers to cache files external to your site, like Javascript files. This can boost performance over slow network connections.
Instructions
-
-
1
Access your web site using a File Transfer Protocol client. Open the client program and create a new connection. Enter your web site address, your user name and password. Press the “Connect” button to connect to your site. The FTP client will list the root directory to your web site.
-
2
Right-click an empty spot in the directory listing. A menu appears.
-
-
3
Select “New File” from the menu. Type in the name “.htaccess.”
-
4
Right-click the “.htaccess” file and select “Edit.” The default text editor for your system opens the “.htaccess” file.
-
5
Type the following statement in the “.htaccess” file, and then save the file.
Header set Cache-Control “public”
The FTP client alters the file on the web site. This statement forces web browsers to cache certain files, like external Javascript files.
-
1
References
- Photo Credit Comstock/Comstock/Getty Images