Skip to content

Commit

Permalink
Adjust cache control
Browse files Browse the repository at this point in the history
  • Loading branch information
TimDaub committed Oct 15, 2024
1 parent 7a1ecc0 commit 0ad73a6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 36 deletions.
6 changes: 3 additions & 3 deletions src/http.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ export async function launch(trie, libp2p) {

reply.header(
"Cache-Control",
"public, max-age=10, stale-while-revalidate=31536000",
"public, s-maxage=10, max-age=10, stale-while-revalidate=31536000",
);
const code = 200;
const httpMessage = "OK";
Expand Down Expand Up @@ -554,7 +554,7 @@ export async function launch(trie, libp2p) {
if (request.params.slug) {
reply.header(
"Cache-Control",
"public, max-age=10, stale-while-revalidate=31536000",
"public, s-maxage=10, max-age=10, stale-while-revalidate=31536000",
);
const queryParams = new URLSearchParams(request.query).toString();
return reply.redirect(`/stories?${queryParams}`);
Expand Down Expand Up @@ -608,7 +608,7 @@ export async function launch(trie, libp2p) {
if (request.query.cached) {
reply.header(
"Cache-Control",
"public, max-age=1, stale-while-revalidate=5",
"public, s-maxage=1, max-age=1, stale-while-revalidate=5",
);
} else {
reply.header("Cache-Control", "no-cache");
Expand Down
33 changes: 0 additions & 33 deletions src/web/src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,38 +164,6 @@ async function addInviteLink(toast) {
}
}

async function addClickCounters() {
const counters = document.querySelectorAll(".click-counter");
if (counters && counters.length > 0) {
const { createRoot } = await import("react-dom/client");
const { StrictMode } = await import("react");
const ClickCounter = (await import("./ClickCounter.jsx")).default;

const wsProtocol = window.location.protocol === "https:" ? "wss" : "ws";
const ws = new WebSocket(`${wsProtocol}://${window.location.host}`);

ws.onmessage = (event) => {
let data;
try {
data = JSON.parse(event.data);
} catch (err) {
return;
}
window.dispatchEvent(new CustomEvent(`click-increment-${data.href}`));
};

counters.forEach((elem) => {
const href = elem.getAttribute("data-story-href");
const clicks = elem.getAttribute("data-story-clicks");
createRoot(elem).render(
<StrictMode>
<ClickCounter href={href} initialClicks={clicks} />
</StrictMode>,
);
});
}
}

async function addDonationRow() {
const donationRow = document.querySelector(".donation-button");
if (!donationRow) return;
Expand Down Expand Up @@ -898,7 +866,6 @@ async function start() {
const results1 = await Promise.allSettled([
addDonationRow(),
addDynamicNavElements(),
addClickCounters(),
addInviteLink(toast),
addCommentInput(toast, await allowlistPromise, await delegationsPromise),
addSubscriptionButton(await allowlistPromise, toast),
Expand Down

0 comments on commit 0ad73a6

Please sign in to comment.