Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
A modern lazy loading library for images.
Follow these steps:
Layzr was developed with a modern JavaScript workflow in mind. Though not required, it's convenient to have a build system in place that can transpile ES6, and bundle modules. For a minimal boilerplate that does so, try outset.
Choose an installation option based on your workflow:
Refer to the releases page for version specific information.
Install Layzr, and add it to your package.json
dependencies.
$ npm install layzr.js --save
Then import
it into the file where you'll use it.
import Layzr from 'layzr.js'
Copy and paste one of the following <script>
tags. Note the version number in the src
attributes.
<script src="https://cdn.jsdelivr.net/layzr.js/2.0.2/layzr.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/layzr.js/2.0.2/layzr.min.js"></script>
Download the latest version, and load the script in the dist
folder.
<script src="layzr.min.js"></script>
Thank you to the community members who created these framework bridges!
Layzr intelligently chooses the best image source available based on an image's data attributes and browser feature detection.
srcset
, if available, it will be used to determine the source.Note that all attribute names are configurable via the options passed to Layzr. To indicate potential sources, add the following attributes to your images:
Name | Required | Optional |
---|---|---|
data-normal | ✓ | |
data-retina | ✓ | |
data-srcset | ✓ |
Put the normal resolution source in the data-normal
attribute.
<img data-normal="normal.jpg">
Note that Layzr selects elements using this attribute. Elements without it won't be tracked, and will never load.
Add the retina/high resolution source in the data-retina
attribute.
<img data-normal="normal.jpg" data-retina="retina.jpg">
Add the source set in the data-srcset
attribute. For information on the proper syntax, read the official specification.
<img data-normal="normal.jpg" data-retina="retina.jpg" data-srcset="small.jpg 320w, medium.jpg 768w, large.jpg 1024w">
Create an instance, optionally passing in your options.
Be sure to assign your Layzr instance to a variable. Using your instance, you can:
// using the default options
const instance = Layzr()
// using custom options
const instance = Layzr({
// ...
})
Options are explained in the following section.
Default options are shown below, and an explanation of each follows:
const instance = Layzr({
normal: 'data-normal',
retina: 'data-retina',
srcset: 'data-srcset',
threshold: 0
})
Customize the attribute the normal resolution source is taken from.
const instance = Layzr({
normal: 'data-normal'
})
Customize the attribute the retina/high resolution source is taken from.
const instance = Layzr({
retina: 'data-retina'
})
Customize the attribute the source set is taken from.
const instance = Layzr({
srcset: 'data-srcset'
})
Adjust when images load, relative to the viewport. Positive values make images load sooner, negative values make images load later.
Threshold is a percentage of the viewport height, identical to the CSS vh
unit.
const instance = Layzr({
threshold: 0
})
Layzr instances are extended with Knot.js, a browser-based event emitter. Use the event emitter syntax to add and remove handlers. Review the emitter syntax here.
Layzr emits the following events:
This event is emitted immediately before an image source is set. The image node is passed to the event handler.
instance.on('src:before', (element) => {
// 'this' is your Layzr instance
// 'element' is the image node
// ...
})
Load event handlers should be attached using this event. See the example, and note the caveats associated with image load events before proceeding.
This event is emitted immediately after an image source is set. The image node is passed to the event handler.
instance.on('src:after', (element) => {
// 'this' is your Layzr instance
// 'element' is the image node
// ...
})
Note that the image is not necessarily done loading when this event fires.
All API methods are chainable, including those from the emitter.
Add or remove the scroll
and resize
event handlers.
instance
.handlers(true) // 'true' adds them
.handlers(false) // 'false' removes them
Manually check if elements are in the viewport.
This method is called while the window
is scrolled or resized.
instance.check()
Update the elements Layzr is checking.
instance.update()
Dynamically added elements should be handled using this method. See the example.
Layzr depends on the following browser APIs:
It supports the following natively:
To support older browsers, consider including polyfills/shims for the APIs listed above. There are no plans to include any in the library, in the interest of file size.
MIT. © 2016 Michael Cavalea
FAQs
A modern lazy loading library for images.
The npm package layzr.js receives a total of 935 weekly downloads. As such, layzr.js popularity was classified as not popular.
We found that layzr.js 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.