Speed up your website: Preloading and caching images

For a customer, I'm building a website that has a pretty large header jpeg that is different for every single page. To speed up loading several pages, I've taken several steps:

1. Force browser caching

You can tell a browser to keep certain files in cache longer than normal. In apache, update the virtual host configuration or put this in a .htaccess file:
<FilesMatch "\.(jpg|jpeg|png|gif|swf|css|ico|js)$">
ExpiresActive On
ExpiresDefault A864000
</FilesMatch>

2. Install libraries

2a jQuery
On this site, I'm using jQuery to perform some tasks. As it was loaded anyway, I can use it for this task as well. So, download jQuery here and install it like:
<script type='text/javascript' src='/lib/jquery.js'></script>

2b jQuery cookie
Download the jQuery cookie plugin (by Klaus Hartl) as well
<script type='text/javascript' src='/lib/jquery.cookie.js'></script>

2c jQuery cookie
The last lib is a image preloading plugin for jQuery, that I found on engineeredweb.com:
(function($) {
var cache = [];
// Arguments are image paths relative to the current page.
$.preLoadImages = function() {
var args_len = arguments.length;
for (var i = args_len; i--;) {
var cacheImage = document.createElement('img');
cacheImage.src = arguments[i];
cache.push(cacheImage);
}
}
})(jQuery)

You can put it in a separate file, for example jquery.preload.js. And again, load it: <script type='text/javascript' src='/lib/jquery.preload.js'></script>

3. Put it all together

jQuery(document).ready(function(){
if(jQuery.cookie("preload")==null){
try{
jQuery.preLoadImages("header1.jpg","header2.jpg");
}catch(e){}
jQuery.cookie("preload",1,{path:"/"})
}
});'

This means:
jQuery(document).ready( = wait until document is completely loaded before starting new downloads.
if(jQuery.cookie("preload")==null){ = only try to fill the cache when cookie 'preload' is not found, ie. once per session
jQuery.cookie("preload",1,{path:"/"}) = set the cookie so this routine will not be executed again during this session.

© GeekLabInfo Speed up your website: Preloading and caching images is a post from GeekLab.info. You are free to copy materials from GeekLab.info, but you are required to link back to http://www.geeklab.info

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

Share one VPN connection

My personal Linux laptop is a real spider in the web. It's got OpenVPN connections to the office, to the datacenter, to serveral family members, etcetera. I love it. But sometimes, there are some tasks that Linux simply can't do, like running a vSphere client.

For those situations, I use the second (Windows) computer on my desk to perform those tasks. However, this computer does not have a VPN connection right to the place I'm connecting to.

Continue Reading…

© GeekLabInfo Share one VPN connection is a post from GeekLab.info. You are free to copy materials from GeekLab.info, but you are required to link back to http://www.geeklab.info

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading...

PXE Boot with old-style dhcp and tftp

In this article I'm covering the use of old-style dhcp and tftp, which is useful for company networks that have/need a complete dhcp server running. Personally, for smaller setups, I now prefer dnsmasq to do the job.

Booting from PXE

With most modern onboard and PCI network interface cards (NICs), it's possible to boot from the network. This system is called PXE.

Why would I want to boot from the network?

  • For installation of a computer without using CDs/DVD's
  • For thin clients
  • For booting diagnostic software
  • What is needed for PXE Boot?

  • a network card that supports PXE
  • a bios that supports plugin boot cards
  • a DHCP server
  • a TFTP server
  • some (open source) software you want to run
  • How to set up PXE boot?

    As I'm running (a variant of) RedHat Linux, I only cover how to set up PXE boot using Linux components. But there are Windows solutions as well. (Google it!)

    Step 1: set up DHCP

    When the NIC boots, it needs to get IP settings. Setup dhcp as usual. Now add these lines to the configuration:
    next-server 192.168.1.254;
    filename "/pxelinux.0";

    In the place of 192.168.1.254, you need to enter your own tftp server address.

    On my RH system, I installed the dhcp server using yum install dhcp, then configured /etc/dhcpd.conf as follows:

    ddns-update-style ad-hoc;
    authoritative;
    log-facility local0;
    default-lease-time 86400;
    max-lease-time 86400;
    subnet 192.168.1.0 netmask 255.255.255.0{
    range 192.168.1.100 192.168.1.200; #limited range
    option subnet-mask 255.255.255.0;
    option broadcast-address 192.168.1.255;
    option routers 192.168.1.254;
    option domain-name-servers 192.168.1.254;
    option domain-name "lan";
    next-server 192.168.1.254;
    filename "/pxelinux.0";
    }

    Step 2: set up TFTP

    Download and install a tftp server. Most Linuxes ship their own, which you can install using yum (RedHat), yast (SuSE), apt-get (debian/ubuntu) or similar.

    On my RedHat, I install a tftp server by running yum install tftp-server. Then I enable it using /sbin/chkconfig tftp on and reload xinetd: /sbin/service xinetd restart.

    Step 3: download and install syslinux

    On my RedHat system, I install syslinux by running yum install syslinux. I then copy the syslinux.0 file to /tftpboot: cp /usr/lib/syslinux/pxelinux.0 /tftpboot

    Optional: Firewall

    On a default RedHat installation, the firewall is enabled. You may need to open port 67-69 for dhcpd and tftp to function and port 53 for DNS.

    Links

    More details are described on
    http://syslinux.zytor.com/wiki/index.php/PXELINUX

    © GeekLabInfo PXE Boot with old-style dhcp and tftp is a post from GeekLab.info. You are free to copy materials from GeekLab.info, but you are required to link back to http://www.geeklab.info

    1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading...

    Running VMWare Remote Console outside the browser

    Firefox 3.6 update broke my VMWare WebAccess.

    Since I updated to Firefox 3.6, I have not been able to run the vmware remote console plugin anymore. Running Linux, this is a pretty important program, as there is no vSphere client for Linux.

    How to run VMWare Console from the bash shell?

    cd /tmp
    IP=the.esx.srv.ip # < fill in esx server ip address here
    wget --no-check-certificate https://$IP/ui/plugin/vmware-vmrc-linux-x86.xpi
    mv vmware-vmrc-linux-x86.xpi vmware-vmrc-linux-x86.zip
    cd ~
    mkdir -p bin/vmwareconsole # make directory bin in your own homedir
    cd bin/vmwareconsole
    unzip /tmp/vmware-vmrc-linux-x86.zip
    cd ~/bin
    ln -s vmwareconsole/plugins/vmware-vmrc . # make a symlink for easy access
    vmware-vmrc # run the console

    © GeekLabInfo Running VMWare Remote Console outside the browser is a post from GeekLab.info. You are free to copy materials from GeekLab.info, but you are required to link back to http://www.geeklab.info

    1 Star2 Stars3 Stars4 Stars5 Stars (11 votes, average: 5.00 out of 5)
    Loading...