question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Usage in apps with SSR (server-side rendering)

See original GitHub issue

Could the detectBrowser function be exported so it could be manually called in a server-side environment?

That way a user agent from a client request could be passed to the detectBrowser function and the resulting detected information could be used on the server before anything is even sent to the client.

I also think it would be a good idea to unify exports into a single file like was requested in #41 for those of us with Node-based projects who use build systems like webpack but not browserify. Couldn’t both options be supported by keeping the browser.js file but adding logic to index.js?

Maybe something like:

var detectBrowser = require('./lib/detectBrowser');

var isClient = !!(typeof window !== 'undefined' && window.document && window.document.createElement)

if (isClient) {
  var agent;
  if (typeof navigator !== 'undefined' && navigator) {
    agent = navigator.userAgent;
  }

  module.exports = detectBrowser(agent);
  module.exports.detectBrowser = null;
} else {
  module.exports.name = 'node';
  module.exports.version = process.version.slice(1);
  module.exports.detectBrowser = detectBrowser;
}

Note that I haven’t test the above, so I can’t guarantee there aren’t issues/errors. Just an idea.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
DamonOehlmancommented, Sep 21, 2017

@dlong500 This is the kind of thing I have started to implement in #46. I just need to rebase this on some recent changes that @5punk has implemented for OS detection and we can look at getting this through.

0reactions
5punkcommented, Oct 30, 2017

Closing due to inactivity. Possibly already solved.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Client-side vs. Server-side vs. Pre-rendering for Web Apps
Server -side rendering allows developers to pre-populate a web page with custom user data directly on the server. It is generally faster to...
Read more >
What is server-side rendering and how does it improve site ...
Server -side rendering (SSR) addresses the performance and search engine optimization issues of single-page JavaScript applications.
Read more >
Improve app performance with React server-side rendering
SSR apps offer faster initial load times and better SEO performance compared to client-side rendered apps, there are some downsides. First, ...
Read more >
From Single-Page Application to Server-Side Rendering |
js server executes the code to deliver HTML achieving the same result without dynamic code being executed in the browser.
Read more >
Server-Side Rendering (SSR) - Vue.js
Vue.js is a framework for building client-side applications. By default, Vue components produce and manipulate DOM in the browser as output.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found