Security News
JavaScript Leaders Demand Oracle Release the JavaScript Trademark
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
ssr-for-bots
Advanced tools
SSR-for-bots is an express middleware that will apply SSR to your application only when bots are visiting it
Basic SSR middleware for Express. Use to prerender your pages for bots so they can read your meta-data if you're using a client side rendering app, or if you want to boost your website SEO score.
Note: this module uses puppeteer. It also stores all the prendered pages to an internal cache store. It's fine for boosting SEO scores, and making the bots able to read meta-data (In case of a React CRA app for example) but it might not produce the desired effect when attempting to use it to serve your pages to users. If you need a more viable solution, I recommend using a framework that uses SSR by default.
$ npm install --save ssr-for-bots
Or if you're using yarn
$ yarn add ssr-for-bots
For a server where the ssr service should be applied:
const ssrForBots = require("ssr-for-bots");
const defaultOptions = {
prerender: [], // Array containing the user-agents that will trigger the ssr service | uses Regex
exclude: [], // Array containing paths and/or extentions that will be excluded from being prerendered by the ssr service | uses Regex
useCache: true, // Variable that determins if we will use page caching or not
cacheRefreshRate: 86400, // Seconds of which the cache will be kept alive, pass 0 or negative value for infinite lifespan
};
// If you're service an API on a route called /api for example add it too the exclude :
// exclude: ["/api/"]
// apply to all requests
app.use(ssrForBots());
// or if you want to use options
app.use(ssrForBots(defaultOptions));
Array containing the user-agents
that will trigger the ssr service uses Regex
.
Note: The array you pass will be added
to the default array list.
Defaults to ["bot","googlebot","Chrome-Lighthouse","DuckDuckBot","ia_archiver","bingbot","yandex","baiduspider","Facebot","facebookexternalhit","facebookexternalhit/1.1","twitterbot","rogerbot","linkedinbot","embedly","quora link preview","showyoubot","outbrain","pinterest","slackbot","vkShare","W3C_Validator"]
.
Array containing the paths
that will be excluded from the ssr service uses Regex
.
Note: The array you pass will be added
to the default array list.
Defaults to [".xml", ".ico", ".txt", ".json"]
.
Example if you're serving an API on /api
path add : ["/api/"]
it will exclude all paths that contains "/api/"
Determins if you want to use cache or not.
The service uses a map to cache all prerendered urls and will return them immediatly if they're cached.
Defaults to true
Cache refresh rate will determine the cache life span expressed in seconds
.
If a page has been cached for more than the cache refresh rate, it will be removed from cache, rerendered and put back to cache right after.
Defaults to 86400
: 24 hours
MIT © Montassar Laribi
FAQs
SSR-for-bots is an express middleware that will apply SSR to your application only when bots are visiting it
The npm package ssr-for-bots receives a total of 8 weekly downloads. As such, ssr-for-bots popularity was classified as not popular.
We found that ssr-for-bots 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
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.