Select templates when first needed, patterns compiled only once, and support for images
JS moved next to HTML