Skip to content

Commit 7374194

Browse files
committed
final opt
1 parent 7d7803d commit 7374194

File tree

8 files changed

+49
-29
lines changed

8 files changed

+49
-29
lines changed

‎index.html‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,21 @@
1010
content="Web site created using create-react-app"
1111
/>
1212
<link rel="apple-touch-icon" href="/logo192.png" />
13+
<link rel="preconnect" href="https://fonts.googleapis.com">
14+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
15+
16+
<!-- Preload required fonts -->
17+
<link rel="preload" as="style" href="https://fonts.googleapis.com/css2?family=Bitter:ital,wght@0,100..900;1,100..900&family=Poppins:wght@200;400;600&family=Roboto+Slab&family=Sedan:ital@0;1&display=swap">
18+
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Bitter:ital,wght@0,100..900;1,100..900&family=Poppins:wght@200;400;600&family=Roboto+Slab&family=Sedan:ital@0;1&display=swap" media="print" onload="this.media='all'">
19+
20+
<noscript>
21+
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Bitter:ital,wght@0,100..900;1,100..900&family=Poppins:wght@200;400;600&family=Roboto+Slab&family=Sedan:ital@0;1&display=swap">
22+
</noscript>
1323
<!--
1424
manifest.json provides metadata used when your web app is installed on a
1525
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
1626
-->
17-
<link rel="manifest" href="/manifest.json" />
27+
<!-- <link rel="manifest" href="/manifest.json" /> -->
1828
<!--
1929
Notice the use of %PUBLIC_URL% in the tags above.
2030
It will be replaced with the URL of the `public` folder during the build.

‎package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"@vitejs/plugin-react": "^4.3.4",
4141
"ajv": "^7.2.4",
4242
"vite": "^6.2.1",
43-
"vite-plugin-compression2": "^1.3.3"
43+
"vite-plugin-compression2": "^1.3.3",
44+
"webpack-bundle-analyzer": "^4.10.2"
4445
}
4546
}

‎src/App.css‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@import url('https://fonts.googleapis.com/css2?family=Bitter:ital,wght@0,100..900;1,100..900&family=Poppins:wght@200;400;600&family=Roboto+Slab&family=Sedan:ital@0;1&display=swap');
1+
@import url('https://fonts.googleapis.com/css2?family=Bitter:ital,wght@0,100..900;1,100..900&family=Poppins:wght@200;400;600&family=Roboto+Slab&family=Sedan:ital@0;1&display=swap&display=swap');
22

33
* {
44
margin: 0;
@@ -54,7 +54,7 @@ h1 {
5454

5555
h2 {
5656
font-family: "Bitter", serif;
57-
font-size: 2.4rem;
57+
font-size: 2.1rem;
5858
}
5959

6060
p {
@@ -260,7 +260,7 @@ button {
260260

261261
.heading {
262262
font-family: 'Bitter';
263-
font-size: '36px';
263+
font-size: 26px;
264264
font-weight: 900;
265265
color: var(--primary-font-color)
266266
}

‎src/App.jsx‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import React, { useEffect, useState, lazy,Suspense } from 'react';
22
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
33

4+
import Navbar from './Navbar'
5+
import Bookmarks from './pages/Bookmarks.jsx';
6+
import Loader from './components/Loader';
7+
48
const Home = lazy(() => import('./pages/Home.jsx'));
5-
const Navbar = lazy(() => import('./Navbar.jsx'));
6-
const Bookmarks = lazy(() => import('./pages/Bookmarks.jsx'));
7-
const Loader = lazy(() => import('./components/Loader.jsx'));
89

910
export const App = () => {
1011
const [theme, setTheme] = useState('light');
@@ -20,12 +21,14 @@ export const App = () => {
2021

2122
return (
2223
<Router>
24+
<Navbar />
2325
<Suspense fallback={<Loader />}>
2426
{/* Navbar */}
25-
<Navbar />
2627

2728
{/* Theme toggle button */}
28-
<button className="theme-switch" onClick={handleClick}>
29+
<button className="theme-switch" onClick={handleClick} aria-label="Toggle Theme"
30+
aria-pressed={theme === 'dark'} aria-labelledby="theme-switch-label"
31+
>
2932
<svg
3033
xmlns="http://www.w3.org/2000/svg"
3134
height="40px"

‎src/Pagination.jsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useCallback } from 'react';
1+
import React, { useState, useCallback, memo } from 'react';
22
import { useGlobalContext } from './Context';
33

44
const Pagination = () => {
@@ -59,4 +59,4 @@ const Pagination = () => {
5959
);
6060
};
6161

62-
export default Pagination;
62+
export default memo(Pagination);

‎src/index.jsx‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
import React from 'react';
1+
import React, { lazy } from 'react';
22
import ReactDOM from 'react-dom/client';
33
import './index.css';
4-
import App from './App'
54
import { AppProvider } from './Context';
65

7-
6+
const App = lazy(()=>import('./App'));
87

98
const root = ReactDOM.createRoot(document.getElementById('root'));
109
root.render(
11-
<React.StrictMode>
1210
<AppProvider>
1311
<App/>
1412
</AppProvider>
15-
</React.StrictMode>
1613
);
1714

‎src/pages/Home.jsx‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
import React from 'react';
2-
import Search from '../Search';
3-
import Stories from '../Stories';
4-
import Pagination from '../Pagination';
5-
import PopularNews from '../PopularNews';
1+
import React,{lazy, Suspense} from 'react';
62
import { useGlobalContext } from '../Context';
73

84
import '../App.css';
95
import "../Navbar.css";
6+
import Loader from '../components/Loader';
7+
8+
const Search = lazy(()=>import('../Search'));
9+
const Stories = lazy(()=>import('../Stories'));
10+
const Pagination = lazy(()=>import('../Pagination'));
11+
const PopularNews = lazy(()=>import('../PopularNews'));
1012

1113
export const Home = () => {
1214
const { showPopularNews } = useGlobalContext();
1315

1416
return (
15-
<>
17+
<Suspense fallback={<Loader />}>
1618
{/* Search bar */}
1719
<Search />
1820

@@ -21,7 +23,7 @@ export const Home = () => {
2123

2224
{/* News sections */}
2325
{showPopularNews ? <PopularNews /> : <Stories />}
24-
</>
26+
</Suspense>
2527
);
2628
}
2729

‎vite.config.js‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
import { defineConfig } from 'vite';
22
import react from '@vitejs/plugin-react';
3-
import { compression } from 'vite-plugin-compression2'
3+
import { compression } from 'vite-plugin-compression2';
44

55
export default defineConfig(() => {
66
return {
77
build: {
88
outDir: 'dist',
9+
sourcemap: false,
910
},
10-
plugins: [react(),compression({
11-
algorithm: 'gzip',
12-
})],
11+
optimizeDeps: {
12+
include: ['react-router-dom'],
13+
},
14+
plugins: [
15+
react(),
16+
compression({
17+
algorithm: 'gzip',
18+
}),
19+
],
1320
};
14-
});
21+
});

0 commit comments

Comments
 (0)