From 54e30b249b4b8dab16aff328a4ca64f0fa37263c Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Fri, 24 Aug 2018 10:54:41 +0200 Subject: [PATCH] SONAR-10952 Use link rel=preconnect to speed up gravatar fetching --- .../src/main/js/app/components/App.tsx | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/server/sonar-web/src/main/js/app/components/App.tsx b/server/sonar-web/src/main/js/app/components/App.tsx index 23211fbae33..22cd429689a 100644 --- a/server/sonar-web/src/main/js/app/components/App.tsx +++ b/server/sonar-web/src/main/js/app/components/App.tsx @@ -26,13 +26,15 @@ import { fetchLanguages } from '../../store/rootActions'; import { fetchMyOrganizations } from '../../apps/account/organizations/actions'; import { getInstance, isSonarCloud } from '../../helpers/system'; import { lazyLoad } from '../../components/lazyLoad'; -import { getCurrentUser, getAppState } from '../../store/rootReducer'; +import { getCurrentUser, getAppState, getGlobalSettingValue } from '../../store/rootReducer'; const PageTracker = lazyLoad(() => import('./PageTracker')); interface StateProps { appState: AppState | undefined; currentUser: CurrentUser | undefined; + enableGravatar: boolean; + gravatarServerUrl: string; } interface DispatchProps { @@ -79,10 +81,22 @@ class App extends React.PureComponent { this.mounted = false; } + renderPreconnectLink = () => { + const parser = document.createElement('a'); + parser.href = this.props.gravatarServerUrl; + if (parser.hostname !== window.location.hostname) { + return ; + } else { + return null; + } + }; + render() { return ( <> - + + {this.props.enableGravatar && this.renderPreconnectLink()} + {isSonarCloud() && } {this.props.children} @@ -92,7 +106,9 @@ class App extends React.PureComponent { const mapStateToProps = (state: any): StateProps => ({ appState: getAppState(state), - currentUser: getCurrentUser(state) + currentUser: getCurrentUser(state), + enableGravatar: (getGlobalSettingValue(state, 'sonar.lf.enableGravatar') || {}).value === 'true', + gravatarServerUrl: (getGlobalSettingValue(state, 'sonar.lf.gravatarServerUrl') || {}).value || '' }); const mapDispatchToProps = ({ -- 2.39.5