Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

Implemented lazy loading

Blue Mouse73a55b62c6e0
diff --git a/src/App.js b/src/App.js
index 62ed2f400..dd9acd977 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,47 +1,37 @@
-import React, { useEffect } from 'react'
+import React, { useEffect, lazy, Suspense } from 'react'
import { Switch, Route, Redirect, useLocation } from 'react-router-dom'
import routes from 'routes'
import { useDispatch, useSelector } from 'react-redux'
import { useAlert } from 'react-alert'
+import cx from 'classnames'
import _some from 'lodash/some'
import _includes from 'lodash/includes'
import Header from 'components/Header'
import Footer from 'components/Footer'
-import MainPage from 'pages/MainPage'
-import SignUp from 'pages/Auth/Signup'
-import SignIn from 'pages/Auth/Signin'
-import ForgotPassword from 'pages/Auth/ForgotPassword'
-import CreateNewPassword from 'pages/Auth/CreateNewPassword'
-import Dashboard from 'pages/Dashboard'
-import Docs from 'pages/Docs'
-import Features from 'pages/Features'
-import UserSettings from 'pages/UserSettings'
-import VerifyEmail from 'pages/Auth/VerifyEmail'
-import ProjectSettings from 'pages/Project/Settings'
-import ViewProject from 'pages/Project/View'
-import Billing from 'pages/Billing'
-import Privacy from 'pages/Privacy'
-import Terms from 'pages/Terms'
import ScrollToTop from 'hoc/ScrollToTop'
-import { isAuthenticated, notAuthenticated } from './hoc/protected'
import { getAccessToken } from 'utils/accessToken'
import { authMe } from './api'
import { authActions } from 'redux/actions/auth'
import { errorsActions } from 'redux/actions/errors'
import { alertsActions } from 'redux/actions/alerts'
-const ProtectedMain = notAuthenticated(MainPage)
-const ProtectedBilling = isAuthenticated(Billing)
-const ProtectedSignIn = notAuthenticated(SignIn)
-const ProtectedSignUp = notAuthenticated(SignUp)
-const ProtectedForgotPassword = notAuthenticated(ForgotPassword)
-const ProtectedNewPasswordForm = notAuthenticated(CreateNewPassword)
-const ProtectedDashboard = isAuthenticated(Dashboard)
-const ProtectedUserSettings = isAuthenticated(UserSettings)
-const ProtectedProjectSettings = isAuthenticated(ProjectSettings)
-const ProtectedViewProject = isAuthenticated(ViewProject)
+const MainPage = lazy(() => import('pages/MainPage'))
+const SignUp = lazy(() => import('pages/Auth/Signup'))
+const SignIn = lazy(() => import('pages/Auth/Signin'))
+const ForgotPassword = lazy(() => import('pages/Auth/ForgotPassword'))
+const CreateNewPassword = lazy(() => import('pages/Auth/CreateNewPassword'))
+const Dashboard = lazy(() => import('pages/Dashboard'))
+const Docs = lazy(() => import('pages/Docs'))
+const Features = lazy(() => import('pages/Features'))
+const UserSettings = lazy(() => import('pages/UserSettings'))
+const VerifyEmail = lazy(() => import('pages/Auth/VerifyEmail'))
+const ProjectSettings = lazy(() => import('pages/Project/Settings'))
+const ViewProject = lazy(() => import('pages/Project/View'))
+const Billing = lazy(() => import('pages/Billing'))
+const Privacy = lazy(() => import('pages/Privacy'))
+const Terms = lazy(() => import('pages/Terms'))
const minimalFooterPages = [
'/projects', '/dashboard', '/settings',
@@ -99,26 +89,28 @@ const App = () => {
<>
<Header authenticated={authenticated} />
<ScrollToTop>
- <Switch>
- <Route path={routes.main} component={ProtectedMain} exact />
- <Route path={routes.signin} component={ProtectedSignIn} exact />
- <Route path={routes.signup} component={ProtectedSignUp} exact />
- <Route path={routes.dashboard} component={ProtectedDashboard} exact />
- <Route path={routes.user_settings} component={ProtectedUserSettings} exact />
- <Route path={routes.verify} component={VerifyEmail} exact />
- <Route path={routes.change_email} component={VerifyEmail} exact />
- <Route path={routes.reset_password} component={ProtectedForgotPassword} exact />
- <Route path={routes.new_password_form} component={ProtectedNewPasswordForm} exact />
- <Route path={routes.new_project} component={ProtectedProjectSettings} exact />
- <Route path={routes.project_settings} component={ProtectedProjectSettings} exact />
- <Route path={routes.project} component={ProtectedViewProject} exact />
- <Route path={routes.billing} component={ProtectedBilling} exact />
- <Route path={routes.docs} component={Docs} exact />
- <Route path={routes.features} component={Features} exact />
- <Route path={routes.privacy} component={Privacy} exact />
- <Route path={routes.terms} component={Terms} exact />
- <Redirect to={routes.main} />
- </Switch>
+ <Suspense fallback={<div className={cx({ 'min-h-page': !isMinimalFooter, 'min-h-min-footer': isMinimalFooter })} />}>
+ <Switch>
+ <Route path={routes.main} component={MainPage} exact />
+ <Route path={routes.signin} component={SignIn} exact />
+ <Route path={routes.signup} component={SignUp} exact />
+ <Route path={routes.dashboard} component={Dashboard} exact />
+ <Route path={routes.user_settings} component={UserSettings} exact />
+ <Route path={routes.verify} component={VerifyEmail} exact />
+ <Route path={routes.change_email} component={VerifyEmail} exact />
+ <Route path={routes.reset_password} component={ForgotPassword} exact />
+ <Route path={routes.new_password_form} component={CreateNewPassword} exact />
+ <Route path={routes.new_project} component={ProjectSettings} exact />
+ <Route path={routes.project_settings} component={ProjectSettings} exact />
+ <Route path={routes.project} component={ViewProject} exact />
+ <Route path={routes.billing} component={Billing} exact />
+ <Route path={routes.docs} component={Docs} exact />
+ <Route path={routes.features} component={Features} exact />
+ <Route path={routes.privacy} component={Privacy} exact />
+ <Route path={routes.terms} component={Terms} exact />
+ <Redirect to={routes.main} />
+ </Switch>
+ </Suspense>
</ScrollToTop>
<Footer minimal={isMinimalFooter} authenticated={authenticated} />
</>
diff --git a/src/pages/Auth/CreateNewPassword/CreateNewPassword.jsx b/src/pages/Auth/CreateNewPassword/CreateNewPassword.jsx
index 00ac57b03..82fde42e1 100644
--- a/src/pages/Auth/CreateNewPassword/CreateNewPassword.jsx
+++ b/src/pages/Auth/CreateNewPassword/CreateNewPassword.jsx
@@ -2,6 +2,7 @@ import React, { useState, useEffect, memo } from 'react'
import { Link, useHistory, useParams } from 'react-router-dom'
import { createNewPassword } from 'api'
+import { notAuthenticated } from '../../../hoc/protected'
import Title from 'components/Title'
import routes from 'routes'
import Input from 'ui/Input'
@@ -124,4 +125,4 @@ const CreateNewPassword = ({
)
}
-export default memo(CreateNewPassword)
+export default notAuthenticated(memo(CreateNewPassword))
diff --git a/src/pages/Auth/ForgotPassword/ForgotPassword.jsx b/src/pages/Auth/ForgotPassword/ForgotPassword.jsx
index c78e5f6e2..eb29b6544 100644
--- a/src/pages/Auth/ForgotPassword/ForgotPassword.jsx
+++ b/src/pages/Auth/ForgotPassword/ForgotPassword.jsx
@@ -3,6 +3,7 @@ import { Link, useHistory } from 'react-router-dom'
import { forgotPassword } from 'api'
import Title from 'components/Title'
+import { notAuthenticated } from '../../../hoc/protected'
import routes from 'routes'
import Input from 'ui/Input'
import Button from 'ui/Button'
@@ -106,4 +107,4 @@ const ForgotPassword = ({
)
}
-export default memo(ForgotPassword)
+export default notAuthenticated(memo(ForgotPassword))
diff --git a/src/pages/Auth/Signin/Signin.jsx b/src/pages/Auth/Signin/Signin.jsx
index 263de5374..97483cb70 100644
--- a/src/pages/Auth/Signin/Signin.jsx
+++ b/src/pages/Auth/Signin/Signin.jsx
@@ -3,6 +3,7 @@ import { Link } from 'react-router-dom'
import PropTypes from 'prop-types'
import Title from 'components/Title'
+import { notAuthenticated } from '../../../hoc/protected'
import routes from 'routes'
import Input from 'ui/Input'
import Button from 'ui/Button'
@@ -132,4 +133,4 @@ Signin.propTypes = {
login: PropTypes.func.isRequired,
}
-export default memo(Signin)
+export default notAuthenticated(memo(Signin))
diff --git a/src/pages/Auth/Signup/Signup.jsx b/src/pages/Auth/Signup/Signup.jsx
index 013481700..ad01813aa 100644
--- a/src/pages/Auth/Signup/Signup.jsx
+++ b/src/pages/Auth/Signup/Signup.jsx
@@ -3,6 +3,7 @@ import { Link } from 'react-router-dom'
import PropTypes from 'prop-types'
import Title from 'components/Title'
+import { notAuthenticated } from '../../../hoc/protected'
import routes from 'routes'
import Input from 'ui/Input'
import Checkbox from 'ui/Checkbox'
@@ -168,4 +169,4 @@ Signup.propTypes = {
signup: PropTypes.func.isRequired,
}
-export default memo(Signup)
+export default notAuthenticated(memo(Signup))
diff --git a/src/pages/Billing/index.jsx b/src/pages/Billing/index.jsx
index 7a2a190e9..2b48879a8 100644
--- a/src/pages/Billing/index.jsx
+++ b/src/pages/Billing/index.jsx
@@ -1,6 +1,7 @@
import React from 'react'
import Pricing from '../MainPage/Pricing'
+import { isAuthenticated } from '../../hoc/protected'
import Title from 'components/Title'
const Features = () => {
@@ -30,4 +31,4 @@ const Features = () => {
)
}
-export default Features
+export default isAuthenticated(Features)
diff --git a/src/pages/Dashboard/Dashboard.jsx b/src/pages/Dashboard/Dashboard.jsx
index b9c3f181a..f8760c4c8 100644
--- a/src/pages/Dashboard/Dashboard.jsx
+++ b/src/pages/Dashboard/Dashboard.jsx
@@ -13,6 +13,7 @@ import { ArrowSmDownIcon } from '@heroicons/react/solid'
import { XCircleIcon } from '@heroicons/react/solid'
import Modal from 'ui/Modal'
+import { isAuthenticated } from 'hoc/protected'
import Title from 'components/Title'
import Loader from 'ui/Loader'
import { ActivePin, InactivePin } from 'ui/Pin'
@@ -186,4 +187,4 @@ Dashboard.defaultProps = {
error: '',
}
-export default memo(Dashboard)
+export default isAuthenticated(memo(Dashboard))
diff --git a/src/pages/MainPage/index.jsx b/src/pages/MainPage/index.jsx
index 56e3fd4d8..73234a2e7 100644
--- a/src/pages/MainPage/index.jsx
+++ b/src/pages/MainPage/index.jsx
@@ -2,6 +2,7 @@ import React from 'react'
import { Link } from 'react-router-dom'
import routes from 'routes'
+import { notAuthenticated } from '../../hoc/protected'
import Title from 'components/Title'
import SignUp from '../Auth/Signup/BasicSignup'
import Pricing from './Pricing'
@@ -247,4 +248,4 @@ const Main = () => (
</Title>
)
-export default Main
+export default notAuthenticated(Main)
diff --git a/src/pages/Project/Settings/ProjectSettings.jsx b/src/pages/Project/Settings/ProjectSettings.jsx
index 2892fbe0d..303e3f034 100644
--- a/src/pages/Project/Settings/ProjectSettings.jsx
+++ b/src/pages/Project/Settings/ProjectSettings.jsx
@@ -1,4 +1,4 @@
-import React, { useState, useEffect, useMemo } from 'react'
+import React, { useState, useEffect, useMemo, memo } from 'react'
import { useLocation, useHistory, useParams } from 'react-router-dom'
import _isEmpty from 'lodash/isEmpty'
import _size from 'lodash/size'
@@ -9,6 +9,7 @@ import _split from 'lodash/split'
import PropTypes from 'prop-types'
import Title from 'components/Title'
+import { isAuthenticated } from '../../../hoc/protected'
import { createProject, updateProject, deleteProject } from 'api'
import Input from 'ui/Input'
import Button from 'ui/Button'
@@ -257,4 +258,4 @@ ProjectSettings.propTypes = {
user: PropTypes.object.isRequired,
}
-export default ProjectSettings
+export default isAuthenticated(memo(ProjectSettings))
diff --git a/src/pages/Project/View/ViewProject.jsx b/src/pages/Project/View/ViewProject.jsx
index 908b35f7a..eceb0c3ab 100644
--- a/src/pages/Project/View/ViewProject.jsx
+++ b/src/pages/Project/View/ViewProject.jsx
@@ -22,6 +22,7 @@ import Title from 'components/Title'
import {
tbPeriodPairs, tbsFormatMapper, getProjectCacheKey,
} from 'redux/constants'
+import { isAuthenticated } from '../../../hoc/protected'
import Button from 'ui/Button'
import Loader from 'ui/Loader'
import Dropdown from 'ui/Dropdown'
@@ -378,4 +379,4 @@ ViewProject.propTypes = {
isLoading: PropTypes.bool.isRequired,
}
-export default memo(ViewProject)
+export default isAuthenticated(memo(ViewProject))
diff --git a/src/pages/UserSettings/UserSettings.jsx b/src/pages/UserSettings/UserSettings.jsx
index b325b4515..6ce828c5d 100644
--- a/src/pages/UserSettings/UserSettings.jsx
+++ b/src/pages/UserSettings/UserSettings.jsx
@@ -11,6 +11,7 @@ import Button from 'ui/Button'
import Modal from 'ui/Modal'
import Select from 'ui/Select'
import { isValidEmail, isValidPassword } from 'utils/validator'
+import { isAuthenticated } from 'hoc/protected'
const UserSettings = ({ onDelete, onExport, onSubmit, onEmailConfirm }) => {
const { user } = useSelector(state => state.auth)
@@ -211,4 +212,4 @@ const UserSettings = ({ onDelete, onExport, onSubmit, onEmailConfirm }) => {
)
}
-export default memo(UserSettings)
+export default isAuthenticated(memo(UserSettings))