mathifonseca / grails-browser-detection Goto Github PK
View Code? Open in Web Editor NEWThis project forked from henadzit/grails-browser-detection
Grails Browser Detection Plugin
License: Apache License 2.0
This project forked from henadzit/grails-browser-detection
Grails Browser Detection Plugin
License: Apache License 2.0
Hi, Is it possible to nest these?
EG:
< browser:choice>
< browser:isNotWindowsMobile>
< browser:isMsie versionLower="9">
...
</ browser:isMsie>
</ browser:isNotWindowsMobile>
</ browser:choice>
Could we create a new release for Grails 2.x with the latest UserAgentUtils?
Because I want to display a message if the browser is not chrome or firefox.
I keep getting this error when building.
I only use added the plugin and got that as a consequence.
Error:(9, 10) Groovyc: Only classes and closures can be used for attribute 'value' in @grails.test.mixin.TestFor
Our application has many instances and many requests per instance in parallel, mostly unique users. Our application is stateless, users are not guaranteed to land on the same application instance next time, there is no session-syncing between the instances.
Our load and performance tests showed after migrating from Grails 2, that there are tons of sessions now. While the specific plugin code did not change since grails 2, we didn't make to configure the session timeouts properly under Grails 3 so far, so the problem became visible.
What the code in question does:
getUserAgent()
wants to check if there is already cached user agent info in the session. Probably to safe a call to safe a call of parseUserAgent()
.
For this it calls
request.session.getAttribute(AGENT_INFO_TOKEN)
which leads to a call of
request.getSession()
which leads to a call of
request.getSession(true)
which creates a session, if there is none.
In our scenario about 90% of the requests don't have a session at this point, unless browser-detection created one in a further call or request.
If there was no user agent session information (or in the very rare cases, where user agent string changed while the session), getUserAgent()
parses the user agent string and ads user agent infos to the (newly created) session.
In our scenario itβs much more expensive to create a session for any unique user on any instance, then just parsing the user agent string on any request.
To cache the agent info for repeated calls of getUserAgent()
within a single request, it would be better to store it in the request scope (request.setAttribute(AGENT_INFO_TOKEN, userAgent)
).
UserAgent getUserAgent() {
String userAgentString = getUserAgentString()
UserAgent userAgent = request.session.getAttribute(AGENT_INFO_TOKEN)
// returns cached instance
if (userAgent && userAgent.userAgentString == userAgentString) {
return userAgent
}
if (userAgent && userAgent.userAgentString != userAgent) {
log.warn "User agent string has changed in a single session!"
log.warn "Previous User Agent: $userAgent.userAgentString"
log.warn "New User Agent: $userAgentString"
log.warn "Discarding existing agent info and creating new..."
}
else {
log.debug "User agent info does not exist in session scope, creating..."
}
// fallback for users without user-agent header
if (userAgentString == null) {
log.warn "User agent header is not set"
userAgentString = ""
}
userAgent = parseUserAgent(userAgentString)
request.session.setAttribute(AGENT_INFO_TOKEN, userAgent)
return userAgent
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.