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.
@anvilco/grunt-embed
Advanced tools
Grunt plugin to convert external scripts and stylesheets into embedded ones.
This is a Grunt plugin wrapper around resource-embedder.
Turns short external scripts and stylesheets into embedded ones:
<script src="foo.js"></script>
becomes <script> ... </script>
<link rel="stylesheet" href="bar.css">
becomes <style> ... </style>
The default behaviour is to embed anything under 5KB in size, but this threshold is configurable.
Should you embed your scripts? Depends. Embedding reduces the number of HTTP requests, and can reduce blocking of subsequent requests and page rendering, but it also means the resources can't be cached individually and shared between pages.
You should do your own measurements to work out if this is a good trade-off in your situation. But, as a guide: short, blocking scripts in the head are often a good candidate for embedding.
A small Modernizr build is a good example: if it's embedded (as a script before your main stylesheet), it will have been executed and applied any special CSS classes to the <html>
tag before your styles are received. Then as soon as the styles are received, any subsequent background-image downloads can be started immediately, because Modernizr's classes will already have been added to the <html>
tag.
This plugin requires Grunt (see Getting Started).
Install:
npm install grunt-embed --save-dev
Load the task in your Gruntfile:
grunt.loadNpmTasks('grunt-embed');
In your Gruntfile, add a section named embed
to the data object passed into grunt.initConfig()
.
grunt.initConfig({
embed: {
options: {
// Task-specific options go here.
},
your_target: {
// Target-specific file lists and/or options go here.
},
},
})
Any options will be passed through to resource-embedder
– see full list of options.
Embed any external scripts and stylesheets under 5KB in size (the default threshold):
grunt.initConfig({
embed: {
some_target: {
files: {
'dest/output.html': 'src/input.html'
}
}
}
})
Custom threshold – embed anything under 3KB in size:
grunt.initConfig({
embed: {
options: {
threshold: '3KB'
},
some_target: {
files: {
'dest/output.html': 'src/input.html'
}
}
}
})
You can use data-embed
attributes to override the options for an individual resource.
<script src="foo.js" data-embed></script> <!-- always embed -->
<script src="foo.js" data-embed="false"></script> <!-- never embed -->
<script src="foo.js" data-embed="10KB"></script> <!-- embed if under 10KB -->
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
(Nothing yet)
Copyright (c) 2013 Callum Locke. Licensed under the MIT license.
FAQs
Grunt plugin to convert external scripts and stylesheets into embedded ones.
We found that @anvilco/grunt-embed demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers 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.