Posts

Showing posts with the label html

Modular HTML pages

Static generation: minimizing how much is re-generated When statically generating HTML content, you face an interesting challenge: If the page frame (the “chrome” of a page) contains information that changes frequently, you need to re-generate all pages every time it does. One example of such information is a top 10 list of the pages that were most popular during the last 30 days. A work-around is to save the information in a separate file and to load that information dynamically via JavaScript. You then have a choice: You can save a JSON file and transform that into HTML or you can save an HTML file and insert it without processing it. Apart from having to re-generate fewer files, you also save traffic, because the shared information only needs to be downloaded once and will be cached, afterwards. Similar: HTTP/2 and JavaScript modules This situation is similar to JavaScript modules. Currently, many modules are bundled (combined) into a single file, to avoid the cost of one connection...

Making checkbox labels clickable via <label>

The <label> element has been around for a while, but I still don’t see enough websites use it. In lets you make labels of checkboxes and radio buttons clickable. Without <label> , you need to click directly on a checkbox in order to toggle it: Some option <input type="checkbox"> Some option If you use <label> , the text after the checkbox becomes clickable: Some option <label><input type="checkbox"> Some option</label> For styling via CSS, you may sometimes need another, more verbose, variant of this element: You can link a label to its control by referring to the control’s ID via the label’s attribute for (thanks to Evgeny Gorbachev for mentioning this use case for this attribute). Some option <style> input:checked + label { color: green; } </style> <input id="check1" type="checkbox"> <label for="check1">Some option</label> <label> works the same for rad...

A new way of delivering Retina images on the web

Recently, high-resolution screens (Apple calls them Retina displays) have become popular – first on cell phones, then on tablets and now on laptops. I have been waiting for those for literally decades: all other computer components (memory, processor speed, etc.) improved predictably, but screen resolutions did not get much better over the years. The problem for web developers is that things look nicely on these displays if resolution-independent mechanism are used: fonts, vector graphics, CSS effects, etc. However, with bitmap graphics, you are forced to deliver images with many more pixels. That has the potential of greatly slowing things down on the web if you are using a Retina device. Daan Jobsis has found an interesting solution: Use a high-resolution JPEG image, but but with an extreme compression rate (e.g. 75%): [...] this image was razor sharp. The difference is even noticable on the iPad 1, 2 and normal computer screens. How bizarre, the filesize is smaller than the orig...