ua-parser-js
ua-parser-js copied to clipboard
Node version should return singleton.
Every module that uses the parser needs to instantiate their own parser:
var UAParser = require('ua-parser-js');
var parser = new UAParser();
// do stuff with parser...
This is wasting some memory, because each module could share the same instance if ua-parser-js
would return a singleton version of the parser, so that you can just do this:
var parser = require('ua-parser-js');
// do stuff with parser...
Hi,
I think that is a very valid point. On the other hand I never (myself) initiate the parser more than once on our system. @Redsandro Why do you need to initiate it multiple times? And in the same environment?
KR, ebbmo
@ebbmo on different routes in different files. Technically the new ...
part could be in a separate custom module, but that would be working around a quirk. It's better to resolve the quirk.
Some modules have this construct. You can recognize them from 20 require
s and 2 new ...
s.
If nothing else, syntactic sugar.
(Slightly late response, not sure if this is still relevant.)