Skip to content

Commit

Permalink
perf: replace axios with unfetch (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
wKovacs64 authored Apr 7, 2020
1 parent ba05cdd commit 5df5f33
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"@use-it/event-listener": "0.1.3",
"@wkovacs64/normalize.css": "8.0.1",
"@xstate/react": "0.8.1",
"axios": "0.19.2",
"dotenv": "8.2.0",
"gatsby": "2.20.13",
"gatsby-plugin-emotion": "4.2.1",
Expand All @@ -65,6 +64,7 @@
"react-icons": "3.9.0",
"typeface-nunito": "1.1.3",
"typeface-source-sans-pro": "1.1.5",
"unfetch": "4.1.0",
"use-dark-mode": "2.3.1",
"xstate": "4.8.0"
},
Expand All @@ -83,6 +83,7 @@
"@types/memoize-one": "5.1.2",
"@types/ms": "0.7.31",
"@types/node": "12.12.34",
"@types/node-fetch": "2.5.5",
"@types/react": "16.9.32",
"@types/react-dom": "16.9.6",
"@types/react-helmet": "5.0.15",
Expand Down
10 changes: 6 additions & 4 deletions src/components/alert-on-update.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from 'react';
import { useStaticQuery, graphql } from 'gatsby';
import axios from 'axios';
import fetch from 'unfetch';
import ms from 'ms';
import styled from '@emotion/styled';
import isMobile from '../utils/is-mobile';
Expand Down Expand Up @@ -41,13 +41,15 @@ const UpdateAlertContainer = styled.div`
const checkForUpdate = async (localCommit: string): Promise<boolean> => {
if (typeof window !== 'undefined') {
try {
const res = await axios.get('/index.html?no-cache=1', {
const res = await fetch('/index.html?no-cache=1', {
method: 'GET',
headers: { Pragma: 'no-cache' },
});
const data = await res.json();

if (res.data) {
if (data) {
const remoteDocument = new DOMParser().parseFromString(
res.data,
data,
'text/html',
);
const remoteCommit = remoteDocument.documentElement.getAttribute(
Expand Down
23 changes: 20 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2651,6 +2651,14 @@
resolved "https://registry.yarnpkg.com/@types/ms/-/ms-0.7.31.tgz#31b7ca6407128a3d2bbc27fe2d21b345397f6197"
integrity sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA==

"@types/[email protected]":
version "2.5.5"
resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.5.5.tgz#cd264e20a81f4600a6c52864d38e7fef72485e92"
integrity sha512-IWwjsyYjGw+em3xTvWVQi5MgYKbRs0du57klfTaZkv/B24AEQ/p/IopNeqIYNy3EsfHOpg8ieQSDomPcsYMHpA==
dependencies:
"@types/node" "*"
form-data "^3.0.0"

"@types/node@*", "@types/node@^12.0.2":
version "12.6.8"
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.6.8.tgz#e469b4bf9d1c9832aee4907ba8a051494357c12c"
Expand Down Expand Up @@ -3628,7 +3636,7 @@ axe-core@^3.1.2:
resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-3.3.0.tgz#3b32d7e54390d89ff4891b20394d33ad7a192776"
integrity sha512-54XaTd2VB7A6iBnXMUG2LnBOI7aRbnrVxC5Tz+rVUwYl9MX/cIJc/Ll32YUoFIE/e9UKWMZoQenQu9dFrQyZCg==

axios@0.19.2, axios@^0.19.2:
axios@^0.19.2:
version "0.19.2"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.2.tgz#3ea36c5d8818d0d5f8a8a97a6d36b86cdc00cb27"
integrity sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==
Expand Down Expand Up @@ -4975,7 +4983,7 @@ combine-source-map@^0.8.0, combine-source-map@~0.8.0:
lodash.memoize "~3.0.3"
source-map "~0.5.3"

combined-stream@^1.0.6, combined-stream@~1.0.6:
combined-stream@^1.0.6, combined-stream@^1.0.8, combined-stream@~1.0.6:
version "1.0.8"
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==
Expand Down Expand Up @@ -7612,6 +7620,15 @@ [email protected]:
tapable "^1.0.0"
worker-rpc "^0.1.0"

form-data@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-3.0.0.tgz#31b7e39c85f1355b7139ee0c647cf0de7f83c682"
integrity sha512-CKMFDglpbMi6PyN+brwB9Q/GOw0eAnsrEZDgcsH5Krhz5Od/haKHAX0NmQfha2zPPz0JpWzA7GJHGSnvCRLWsg==
dependencies:
asynckit "^0.4.0"
combined-stream "^1.0.8"
mime-types "^2.1.12"

form-data@~2.3.2:
version "2.3.3"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.3.3.tgz#dcce52c05f644f298c6a7ab936bd724ceffbf3a6"
Expand Down Expand Up @@ -16152,7 +16169,7 @@ undeclared-identifiers@^1.1.2:
simple-concat "^1.0.0"
xtend "^4.0.1"

unfetch@^4.0.0, unfetch@^4.0.1:
unfetch@4.1.0, unfetch@^4.0.0, unfetch@^4.0.1:
version "4.1.0"
resolved "https://registry.yarnpkg.com/unfetch/-/unfetch-4.1.0.tgz#6ec2dd0de887e58a4dee83a050ded80ffc4137db"
integrity sha512-crP/n3eAPUJxZXM9T80/yv0YhkTEx2K1D3h7D1AJM6fzsWZrxdyRuLN0JH/dkZh1LNH8LxCnBzoPFCPbb2iGpg==
Expand Down

0 comments on commit 5df5f33

Please sign in to comment.