Security News
The Push to Ban Ransom Payments Is Gaining Momentum
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
ab-interchange
Advanced tools
Readme
AB-interchange is a vanilla JavaScript that makes possible conditionnaly loading depending on media queries:
It's damn small: about 1800 bytes (uglyfied and GZipped).
That plugin also has an lazy-loading option!
> npm install ab-interchange
or
> yarn add ab-interchange
It's used on French website ENGIE.
Just load the script on your page, just before </body>
.
No need to load another-brick or AB-mediaQuery since they are already included into AB-interchange. You can use their features of course (read respective readme).
The best solution is to use browserify or Webpack and import 'abInterchange'.
import abInterchange from 'ab-interchange';
Because of the usage of matchMedia
and requestAnimationFrame
, compatibility start with IE 10. To rise compatibility up to IE 9, you can add matchMedia polyfill and requestAnimationFrame polyfill.
Follow AB-mediaQuery readme to configure it the way you like depending on your needs. For exemple:
abMediaQuery({
bp: {
smallOnly: 'screen and (max-width: 767px)',
mediumOnly: 'screen and (min-width: 768px) and (max-width: 1024px)',
medium: 'screen and (min-width: 768px)',
largeOnly: 'screen and (min-width: 1025px) and (max-width: 1280px)',
large: 'screen and (min-width: 1025px)'
}
});
Then you only need to initialize with AB.interchange()
or with some options:
abInterchange({
lazy : true, // or false
offscreen : 1.5, // load items only when in the view + 0.5 by default
});
Then use data-ab-interchange attribute to pass otpions individually.
data-ab-interchange-src attribute is where you define different sources and breakpoints defined with AB-mediaQuery. It should contain a list of arrays with the path to the asset and the breakpoint name. Beware to respect mobile first order. Order is VERY important!
<picture>
<source srcset="xxx" media="(min-width: 80em)"/>
<source srcset="xxx" media="(min-width: 64em)"/>
<source srcset="xxx" media="(min-width: 48em)"/>
<source srcset="xxx"/>
<img
alt=""
data-ab-interchange='{"lazy": false}"
data-ab-interchange-src="[xxx, smallOnly], [xxx, medium]"/>
</picture>
<img
alt=""
data-ab-interchange='{"lazy": false}"
data-ab-interchange-src="[xxx, smallOnly], [xxx, medium]"/>
<div
data-ab-interchange='{"mode": "background", "lazy": true, "offscreen": 1.5}"
data-ab-interchange-src="[xxx, smallOnly], [xxx, medium]">
</div>
<div
data-ab-interchange="{"mode": "ajax", "lazy": false}"
data-ab-interchange-src="[xxx, smallOnly], [xxx, mediumOnly]">
</div>
'replaced.ab-interchange' event is automatically triggered when an IMG (or else) changed. For IMG and HTML, it's fired only when the new content is loaded, for background-image, immediatly, because it does not impact the layout:
window.addEventListener('replaced.ab-interchange', function(e){
console.log(e.detail.element);
});
FAQs
AB-interchange: While responsive image loading is not really an easy task even today, here is a solution to manage conditional (based on breakpoints) loading of img, background-image or even HTML content.
We found that ab-interchange demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
Application Security
New SEC disclosure rules aim to enforce timely cyber incident reporting, but fear of job loss and inadequate resources lead to significant underreporting.
Security News
The Python Software Foundation has secured a 5-year sponsorship from Fastly that supports PSF's activities and events, most notably the security and reliability of the Python Package Index (PyPI).