Skip to content

Commit

Permalink
defer tw script
Browse files Browse the repository at this point in the history
  • Loading branch information
GraemeFulton committed May 3, 2024
1 parent c108e2b commit b73e51c
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 44 deletions.
11 changes: 6 additions & 5 deletions components/Editor/editorHooks/libs/addTwitterScript.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
export const addTwitterScript = () => {
const s = document.createElement("script");
s.setAttribute("src", "https://platform.twitter.com/widgets.js");
s.setAttribute("id", "twitter-widget");
s.setAttribute("async", "true");

if (!document.getElementById("twitter-widget")) {
const s = document.createElement("script");
s.setAttribute("src", "https://platform.twitter.com/widgets.js");
s.setAttribute("id", "twitter-widget");
s.setAttribute("async", "true");
s.setAttribute("defer", "true")

document.head.appendChild(s);
}
};
1 change: 0 additions & 1 deletion components/meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ export default function Meta({ seo, articleJsonLd, productJsonLd }) {

{/* CODEPEN AND TWITTER EMBED */}
{typeof window &&<script defer async="async" src="https://static.codepen.io/assets/embed/ei.js"></script>}
{typeof window &&<script defer async="async" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>}

</>
);
Expand Down
23 changes: 21 additions & 2 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
// const { withSentryConfig } = require('@sentry/nextjs');


import withPlaiceholder from "@plaiceholder/next";
import { withPlausibleProxy } from "next-plausible";

// import withBundleAnalyzer from '@next/bundle-analyzer';
// const bundleAnalyzer = withBundleAnalyzer({
// enabled: process.env.ANALYZE === 'true',
// })

const isProd = process.env.NODE_ENV === "production";

const nextConfig =
// module.exports =
Expand Down Expand Up @@ -176,6 +175,8 @@ const nextConfig =
browsersListForSwc: true,
// optimizePackageImports: ['@phosphor-icons/react']
},
// assetPrefix: isProd ? 'https://prototyprio.gumlet.io' : undefined,
// assetPrefix: 'https://prototyprio.gumlet.io',
images: {
loader: "custom",
loaderFile: "./lib/imageloader.js",
Expand All @@ -202,6 +203,24 @@ const nextConfig =
"sfo2.digitaloceanspaces.com",
],
},
//cache https://focusreactive.com/configure-cdn-caching-for-self-hosted-next-js-websites/#:~:text=Configuring%20Cloudflare%20CDN%20for%20the%20Next.&text=To%20configure%20HTML%20page%20caching,)%2C%20and%20Edge%20TTL%20section.
async headers() {
if (process.env.NODE_ENV !== "production") {
return [];
}
return [
{
source: "/:all*(css|js|gif|svg|jpg|jpeg|png|woff|woff2)",
locale: false,
headers: [
{
key: "Cache-Control",
value: "public, max-age=31536000",
},
],
},
];
},
// generation before timing out
staticPageGenerationTimeout: 300000,
});
Expand Down
11 changes: 3 additions & 8 deletions pages/post/[slug].js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { TOTAL_STATIC_POSTS } from "@/lib/constants";
import PostHeader from "@/components/post-header";
import SocialShare from "@/components/SocialShare";
import PostGroupRow from "@/components/v4/layout/PostGroupRow";
import { addTwitterScript } from "@/components/Editor/editorHooks/libs/addTwitterScript";
const StickyFooterCTA = dynamic(() => import("@/components/StickyFooterCTA"), {
ssr: false,
});
Expand Down Expand Up @@ -93,14 +94,8 @@ export default function Post({ post, preview, relatedPosts, postContent }) {
const intl = useIntl();

useEffect(() => {
const s = document.createElement("script");
s.setAttribute("src", "https://platform.twitter.com/widgets.js");
s.setAttribute("id", "twitter-widget");
s.setAttribute("async", "true");

if (!document.getElementById("twitter-widget")) {
document.head.appendChild(s);
}

addTwitterScript();

if (window.$crisp) {
// window.$crisp.push(["config", "position:reverse", true])
Expand Down
12 changes: 3 additions & 9 deletions pages/toolbox/[slug].js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import buildToolboxGallery, {
import { formatAllTools } from "@/lib/utils/formatToolContent";
import ToolIconCard from "@/components/v4/card/ToolIconCard";
import HeroCardSection from "@/components/toolbox/HeroCardSection";
import { addTwitterScript } from "@/components/Editor/editorHooks/libs/addTwitterScript";

const ToolContent = ({
post,
Expand All @@ -70,15 +71,8 @@ const ToolContent = ({
const tags = post.attributes.tags.data;

useEffect(() => {
const s = document.createElement("script");
s.setAttribute("src", "https://platform.twitter.com/widgets.js");
s.setAttribute("id", "twitter-widget");
s.setAttribute("async", "true");

if (!document.getElementById("twitter-widget")) {
document.head.appendChild(s);
}


addTwitterScript();
if (window.$crisp) {
// window.$crisp.push(["config", "position:reverse", true])
// window.$crisp.push(['do', 'chat:close']);
Expand Down
17 changes: 0 additions & 17 deletions pages/web-monetization/payment-pointer.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,6 @@ export default function Post({ post, preview, relatedPosts }) {

const intl = useIntl();

useEffect(() => {
const s = document.createElement("script");
s.setAttribute("src", "https://platform.twitter.com/widgets.js");
s.setAttribute("id", "twitter-widget");
s.setAttribute("async", "true");

if (!document.getElementById("twitter-widget")) {
document.head.appendChild(s);
}

if(window.$crisp){
// window.$crisp.push(["config", "position:reverse", true])
// window.$crisp.push(['do', 'chat:close']);
window.$crisp.push(['do', 'chat:hide']);
}

}, []);

return (
<Layout
Expand Down
2 changes: 0 additions & 2 deletions styles/index.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&family=Noto+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,400&family=Noto+Serif:ital,wght@0,400;0,700;1,400&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,400&family=Noto+Serif:ital,wght@0,400;0,700;1,400&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;0,500;&display=swap');

@tailwind base;

Expand Down

0 comments on commit b73e51c

Please sign in to comment.