@@ -30,6 +30,40 @@ export type SpeedPoint = {
30
30
31
31
### Speed Test
32
32
33
+ A 30 MB file is hosted on a GitHub Pages site with a custom domain. The custom
34
+ domain allows CORS requests, which is necessary for the speed test to work.
35
+
36
+ ``` ts
37
+ const response = await fetch (
38
+ ` https://speed-test-files.zzzzion.com/data-30-mb.txt?timestamp=${Date .now ()} `
39
+ );
40
+ const downloadData = await response .blob (); // Get the file as a Blob
41
+ ```
42
+
43
+ The fetch request is timed to measure the download speed.
44
+
45
+ The same file is then uploaded to a Cloudflare Worker, hosted at
46
+ [ speed-test-upload.zzzzion.workers.dev] ( https://speed-test-upload.zzzzion.workers.dev/ ) .
47
+
48
+ ``` js
49
+ addEventListener (" fetch" , (event ) => {
50
+ event .respondWith (handleRequest (event .request ));
51
+ });
52
+
53
+ async function handleRequest (request ) {
54
+ if (request .method === " POST" ) {
55
+ const formData = await request .formData ();
56
+ const file = formData .get (" file" );
57
+ return new Response (" File uploaded and processed" , { status: 200 });
58
+ }
59
+ return new Response (" Method not allowed" , { status: 405 });
60
+ }
61
+ ```
62
+
63
+ This measures the time it takes to upload the file to Cloudflare's Edge network.
64
+
65
+ #### Old method
66
+
33
67
User's network speed is testing by generating dummy 25 MB data using a Next.js
34
68
API route. The frontend requests the speed test endpoint, and measures the time
35
69
it takes to download the data. It then uploads the same data back to the server
0 commit comments