[ 
https://issues.apache.org/jira/browse/KNOX-3025?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17830987#comment-17830987
 ] 

Aviv Keller commented on KNOX-3025:
-----------------------------------

I also removed the *userAgent* variable, as it is never used
h1. 'get'

Renamed to *getQueryParam* for readability, which will help debugging users 
understand the code

Changed to use {*}URLSearchParams{*}, which is _3.58%_ faster.

Benchmark at [https://jsbench.me/z1lu8i81cc/1]

 
h1. 'testSameOrigin'

Renamed to *isSameOrigin* to better describe what the result will reference

Added a *b* parameter in case the origin needs to be a different URL in the 
future

Changed to use {*}URL{*}, which has fewer document calls and is around the same 
speed as the older function

Benchmark at [https://jsbench.me/q8lu8irzqn/1]

 
h1. 'redirect'

Removed the *try/catch* clause, as *window.location.replace* can be relied on 
entirely. This is just the removal of redundant code.

 
h1. 'login'

Because of the complexity of this code, I did not make a benchmark. Still, my 
changes intend to accomplish the same as the original code while increasing the 
readability and efficiency of the code. Such changes include using array tools 
to check for the status codes, not relying on *ActiveXObject* as a backup, and 
more.

 
h1. 'handleError'

I added this function using the code that runs on an error during the login 
process and changed the code to rely on native JS functions rather than jQuery, 
as it is unnecessary to use an external library for what can be accomplished in 
plain JS. 

 

Overall, these changes should increase the readability, speed, and robustness 
of the knoxauth.js file.

> Use newer browser features in knoxauth.js + Removal of used variables
> ---------------------------------------------------------------------
>
>                 Key: KNOX-3025
>                 URL: https://issues.apache.org/jira/browse/KNOX-3025
>             Project: Apache Knox
>          Issue Type: Improvement
>            Reporter: Aviv Keller
>            Priority: Minor
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> The knoxauth.js file currently utilizes outdated and inefficient browser 
> features. It could be optimized by leveraging newer, more efficient 
> alternatives.
> Details:
>  - Rename the 'get' function to 'getQueryParam' and implement it using 
> URLSearchParams for clarity and efficiency.
>  - Update the 'isSameOrigin' function to utilize URL instead of 
> document.create("a") for improved performance.
>  - Fully rely on window.location.replace for redirect operations to enhance 
> efficiency and reliability.
>  - Implement newer techniques in the 'login' function to achieve the desired 
> outcome more efficiently.
>  - Replace jQuery usage with native features to improve speed and reduce 
> complexity in the codebase.
>  - And more
> [https://github.com/apache/knox/pull/892/]



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to