Usage in apps with SSR (server-side rendering)
See original GitHub issueCould 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:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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.
Closing due to inactivity. Possibly already solved.