Skip to content

Commit f406aab

Browse files
authored
refactor: only declare and initialise the header variable if we are going to use it (#88)
this is a tiny performance optimisation. Previously we would declare and initialise the `header` variable, and we might not have used it because the response could be non-html. this patch relocates this variable declaration to happen after we have figured out the response is html
1 parent 15abadd commit f406aab

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/__csp-nonce.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ const params = inputs as Params;
2121
const handler = async (request: Request, context: Context) => {
2222
const response = await context.next(request);
2323

24-
let header = params.reportOnly
25-
? "content-security-policy-report-only"
26-
: "content-security-policy";
27-
2824
// for debugging which routes use this edge function
2925
response.headers.set("x-debug-csp-nonce", "invoked");
3026

@@ -40,6 +36,10 @@ const handler = async (request: Request, context: Context) => {
4036
return response;
4137
}
4238

39+
let header = params.reportOnly
40+
? "content-security-policy-report-only"
41+
: "content-security-policy";
42+
4343
// CSP_NONCE_DISTRIBUTION is a number from 0 to 1,
4444
// but 0 to 100 is also supported, along with a trailing %
4545
// @ts-ignore

0 commit comments

Comments
 (0)