Image Preloader

This is a neat trick which I found (and subsequently used) here.

Basically this is a small jQuery snippet which goes through your stylesheets and looks for images and caches them, so that they are not loaded when the user interacts with a link, logo, overlay window etc.

Here it is:

function preLoadImages () {
    $.get($('link[rel="stylesheet"]')[0].href, function(data){
        r = /url\(['|"]?(\S+\.(gif|jpg|jpeg|png)[^'(]*)['|"]?\)/ig;
        while (match = r.exec(data)){
            var cacheImage = document.createElement('img');
            cacheImage.src = match[1];
        }
   });
}
preLoadImages();

Getting data into a Django application on Heroku

You can use Django to dump data from your db and git to push the dump to heroku. If the data is sensitive you should take care to remove the data by resetting the head after loading the data in heroku. A more in depth solution can be found here.

1. Dumpdata from dev build.

python manage.py dumpdata --natural --indent 2 > data.json

2. Add data to repo and commit.

git add data.json

git commit -m "Dump data"

3. Push to Heroku.

git push heroku master

4. Load data into Heroku build.

heroku run python manage.py loaddata data.json