@bicycle-codes/image-element
v0.0.4
Published
A webcomponent that uses the 'blur up' technique
Downloads
10
Readme
image element
Use the blur-up technique with images, as a web component.
This depends on having some inline base64 code for a small, blurry image. See @bicycle-codes/stringify for help with that.
install
npm i -S @bicycle-codes/image-element
demonstration
See a demonstration here: bicycle-codes.github.io/image-element.
[!TIP] Throttle the internet speed with the dev tools.
use
Import this module, then use the tag in your HTML. It should work with all contemporary image attributes.
bundler
Just import the module; it will call the global customElements.define
function. Also, import the styles.
import '@bicycle-codes/image-element'
import '@bicycle-codes/image-element/style.css'
Then use the tag in your HTML:
<body>
<image-element
src="/100.jpg"
placeholder="data:image/jpeg;base64,/9j/2wBDAAYEBQY..."
></image-element>
</body>
HTML
This package includes minified CSS and JS files, suitable for linking to directly from your HTML.
First make sure the files are accessible by your web server:
cp ./node_modules/@bicycle-codes/image-element/dist/index.min.js ./public/image-element.js
cp ./node_modules/@bicycle-codes/image-element/dist/style.min.css ./public
Then link to it in your HTML:
<head>
<!-- include the style -->
<link rel="stylesheet" href="/style.min.css">
</head>
<body>
<image-element
src="/100.jpg"
placeholder="data:image/jpeg;base64,/9j/2wBDAAYEBQYFBAYGBQY..."
></image-element>
<!-- include the JS -->
<script src="./image-element.js"></script>
</body>
develop
Start a local dev server:
npm start
see also
- industrialempathy.com/image-optimizations
- bholmes.dev/picture-perfect-image-optimization/
- css-tricks -- The “Blur Up” Technique for Loading Background Images
- css-tricks -- the
sizes
attribute tldr; = "It’s actually not that bad to just leave it off. In that case, it assumes sizes='100vw'." - cloudfour.com -- Don’t use
<picture>
(most of the time) - css-tricks -- Responsive Images: If you’re just changing resolutions, use srcset.