Toby's Log page 90

Check request compression savings

Gzip compression is almost universally recommended as a basic step to improving site performance. It basically uses a little bit of extra processing on the server and client to significantly reduce the transfer size of most text responses. In Apache, this is done with mod_deflate (see the H5BP config for an example of how to set this up).

A while back, I was setting gzip up on my server, and wanted a simple way to verify that it was working and check how much transfer was saved. One simple way to verify it is working is with curl on the command line. If you run curl -I -H 'Accept-Encoding: gzip,deflate' example.com and see the header Content-Encoding: gzip, compression is working. To test the transfer savings, I wrote a simple script using PHP’s curl library. It makes a request with and without the Accept-Encoding: gzip,deflate header, and compares the transfer data info provided by curl_getinfo().

Continue reading post "Check request compression savings"

I feel as if my mind has grown more cloudy and gray as I’ve gotten older. When I was younger, I had ideas coming to me all the time. I was able to take in new things easily, understand things, connect things. I was more idealistic. The future seemed more open. Reality, the mundane operations of going to work, paying bills, cleaning, taxes, all the adult things have taken focus. Life has always been a tunnel, but now it seems a more narrowly defined tunnel. It seems hard to make any headway toward anything that seems like real progress.


Raspberry Pi: playing with BerryBoot, RetroPie, and OpenElec

Played with my Raspberry Pi a bit more this weekend. I bought another micro-SD card and installed BerryBoot, a bootloader / OS installer sort of like Noobs, on it.

I installed RetroPie, a project that is built on top of Raspbian but with numerous emulators and a special interface that can be operated by a gamepad. It seems like it would be cool to condense all of my video game systems and even my oldest Mac (an SE) into a tiny box. Unfortunately, I wasn’t able to do much with it since I have to figure out how to get games onto it. It doesn’t have a web browser or other normal Linux stuff accessible from its special interface.

I also installed OpenElec, a media center. It has a dedicated interface meant to be operated by a remote control, though since I don’t have one of those, it operates a bit slowly by mouse. It has various media applications that can be installed from its interface, basically one for each of any online services. I installed quite a few and watched some old commercials on GetTV.

I’m thinking maybe I’ll eventually get a second Raspberry Pi to use as a media / gaming center. It’s easy to dual boot them using BerryBoot. It would be cooler if I could figure out a way to more easily switch between them, rather than rebooting. opensource++


Logging service worker cache headers

As part of the service worker API, a cache interface has been provided to manage cached request-response pairs. In working on the service worker for my site, I wanted to see what headers the cached requests and responses had, but due to the asynchronous way many of the cache properties are accessed, this was a bit verbose. I wrote out a script that I could paste in the JS console to look at all stored request-response pairs in a given cache so I could examine them:

caches.open('cache-name').then(function(_cache){ 
    _cache.keys().then(function(_keys){ 
        _keys.forEach(function(_request){
            var _requestLog = [];
            _requestLog.push(['request', _request.url, _request]); 
            _request.headers.forEach(function(){ 
                _requestLog.push(['request header', arguments]); 
            }); 
            _cache.match(_request).then(function(_response){ 
                _requestLog.push(['reponse', _response]); 
                _response.headers.forEach(function(){ 
                    _requestLog.push(['response header', arguments]); 
                }); 
            }).then(function(){
                _requestLog.forEach(function(_item){
                    console.log.apply(console, _item);
                });
            });
        });
    }); 
});

Replace cache-name with whatever key you’re using for your cache. Be warned that this will produce a long log if you’ve got more than a few items in the cache. You can also see just the requests you have a cache for with something like:

caches.open('cache-name').then(function(_cache){ 
    _cache.keys().then(function(_keys){ 
        _keys.forEach(function(_request){
            console.log(['request', _request.url, _request]); 
        });
    }); 
});

Self-signed certificate for testing

In playing with service workers, I set up a self-signed SSL certificate for my local development environment. I used instructions from debian.org. It was very simple, since I didn’t need the security involved with a real operating site. Creating the certs took a single command:

openssl req -new -x509 -days 365 -nodes -out /path/to/server/config/certs/sitename.pem -keyout /path/to/server/config/certs/sitename.key

You then just need to set things up in the server configuration (Apache in my case). mod_ssl must be installed and enabled, which looks something like:

Continue reading post "Self-signed certificate for testing"

</toby>