1. Kyle Mahan

    Made two minor speed improvements to last night.

    First, I started resizing foreign avatars when mirroring them to the local server. So now repoy contexts and sparklines don’t have to load the person’s full resolution picture. This is also nicer when viewing through a feed reader like photo.jpgBarnaby Walters‘s Shrewdness where my CSS is obviously not available.

    The larger improvement came from using the nginx header X-Accel-Redirect when sending images associated with posts. This allows images to serve directly from nginx and without passing through Python, even though they are not in the static folder (and can even be protected by access controls).

    In the following two configurations to nginx, internal means that these URLs are not accessible unless there is an internal redirect to them. alias means that resources at https://kylewm.com/internal_data/{some/path} will be served from /home/kmahan/redwind/redwind/_data/{some/path}

    location /internal_data {
        internal;
        alias /home/kmahan/redwind/redwind/_data;
        expires 30d;
    }
    
    location /internal_resized {
        internal;
        alias /home/kmahan/redwind/redwind/_resized;
        expires 30d;
    }
    

    The change in my blog code was pretty trivial. Instead of calling Flask’s send_from_directory to proxy all those bytes through Python, I instead send back an empty response with X-Accel-Redirect header.

    resp = make_response('')
    resp.headers['X-Accel-Redirect'] = '/internal' + sourcepath
    del resp.headers['Content-Type']
    return resp
    

    Removing the Content-Type header means that nginx will decide what content type to send.

    Thanks main_image.jpgMatt Spitz for the super helpful post on the subject!

  2. http://acegiak.net

    With the new facebook browser or extension! Specifically to allow facebook originated cross site scripting!