使用的nextjs 版本為14.0.1
我在api設計有設定no-store
import { OauthHeader } from "@/tools/auth";
import { NextResponse } from "next/server";
export const GET = async () => {
const url = `${process.env.URL}`;
const method = "GET";
try {
const headers = await OauthHeader(url, method);
const res = await fetch(url, {
method,
headers: {
...headers,
},
cache: "no-store",
});
const { responseMsgs } = await res.json();
return NextResponse.json(responseMsgs);
} catch (e) {
return NextResponse.json(e);
}
};
我在ServerComponent有設定no-store
import InvList from "@/app/components/InvList";
const InvoicePage = async () => {
let data = null;
try {
const url = `${process.env.NEXT_PUBLIC_LOCALBACKENDAPIURL}`;
const res = await fetch(url, { cache: "no-store" });
data = await res.json();
} catch (e) {
console.log(e.message);
}
return <>{data && <InvList invoices={data} />}</>;
};
export default InvoicePage;
想請問我在dev階段,進入畫面時都有loading出現
但是在build完start專案後,畫面都是一下就出現,感覺都沒有重新讀取api,想請問為什麼都還會有快取
next.config.js
加上這段
module.exports = {
headers: () => [
{
source: '/:path*',
headers: [
{
key: 'Cache-Control',
value: 'no-store',
},
],
},
],
}
然後確定取到 cache
的原因是因為感覺很快,所以認定為 cache
?
還是用其他方式確定到取到的是 cache
?