2022年6月1日 星期三

雅特力 針對網頁cache提出的解決方案

 雅特力 針對網頁cache提出的解決方案: (2022/6/1)


你們可以在HTTP response的header加上cache-control


有加跟沒加差別就是client端第二次之後會不會從cache中抓資料

可以參考LwIP的官方範例,它的HTML source code中有包含HTTP的header, 不過沒有加上Cache-Control必須要自己添加

加上HTTP header

HTTP/1.0 200 OK

Server: lwIP/2.0.3d (http://savannah.nongnu.org/projects/lwip)

Cache-Control: max-age=31536000

Content-Length: 1751

Content-Type: text/html

length要麻煩你自己計算


BSP的代碼:

/* HTTP header */

/* "HTTP/1.0 200 OK

" (17 bytes) */

0x48,0x54,0x54,0x50,0x2f,0x31,0x2e,0x30,0x20,0x32,0x30,0x30,0x20,0x4f,0x4b,0x0d,

0x0a,

/* "Server: lwIP/2.0.3d (http://savannah.nongnu.org/projects/lwip)

" (64 bytes) */

0x53,0x65,0x72,0x76,0x65,0x72,0x3a,0x20,0x6c,0x77,0x49,0x50,0x2f,0x32,0x2e,0x30,

0x2e,0x33,0x64,0x20,0x28,0x68,0x74,0x74,0x70,0x3a,0x2f,0x2f,0x73,0x61,0x76,0x61,

0x6e,0x6e,0x61,0x68,0x2e,0x6e,0x6f,0x6e,0x67,0x6e,0x75,0x2e,0x6f,0x72,0x67,0x2f,

0x70,0x72,0x6f,0x6a,0x65,0x63,0x74,0x73,0x2f,0x6c,0x77,0x69,0x70,0x29,0x0d,0x0a,


/* "Cache-Control: max-age=31536000

" (33 bytes) */

0x43, 0x61, 0x63, 0x68, 0x65, 0x2D, 0x43, 0x6F, 0x6E, 0x74, 0x72, 0x6F, 0x6C, 0x3A, 

0x20, 0x6D, 0x61, 0x78, 0x2D, 0x61, 0x67, 0x65, 0x3D, 0x33, 0x31, 0x35, 0x33, 0x36, 

0x30, 0x30, 0x30, 0x0d, 0x0a,

  

/* "Content-Length: 1751

" (18+ bytes) */

0x43,0x6f,0x6e,0x74,0x65,0x6e,0x74,0x2d,0x4c,0x65,0x6e,0x67,0x74,0x68,0x3a,0x20,

0x31,0x37,0x35,0x31,0x0d,0x0a,

/* "Content-Type: text/html


" (27 bytes) */

0x43,0x6f,0x6e,0x74,0x65,0x6e,0x74,0x2d,0x54,0x79,0x70,0x65,0x3a,0x20,0x74,0x65,

0x78,0x74,0x2f,0x68,0x74,0x6d,0x6c,0x0d,0x0a,0x0d,0x0a,


把這段貼到你的每個HTML代碼前面試試 length改成正確的數值

範例中 ADC頁面有問題請不要測試,main page跟LED之間的切換是正常的

可以參考上圖修改每個對應的html/css/js檔

(https://drive.google.com/file/d/1bttoZ3c7rRPr_bWLez3v2o3koMQslZVr/view?usp=sharing)

沒有留言:

張貼留言