ทำความเข้าใจเรื่อง การ Clear Browser Cache
เวลาเราใช้ Browser เพื่อเข้าสู่ Website นั้น
ในครั้งแรกที่เราไปเข้า website ที่ไม่เคยเข้า Browser จะไปเอาข้อมูลจริงๆ มาไว้ที่เครื่องเราด้วย
ดังนั้น Status ของ HTTP status code จะเท่า 200 OK คือ ไปดึงข้อมูลล่าสึดมาจาก website จริงๆ
ซึ่ง แต่ละหน้า Webpage จะประกอบด้วยหลายๆ component หลายส่วน เช่น Code html , Java Script , รูปภาพ , VDO , Flash , ไฟล์เสียง
จากรูปข้างล่างจะแสดงให้เห็นว่า Page หน้านี้ ต้องไปดึง component มาทั้งหมด 98 ตัว และต้องใช้ traffic 4.2 MB ในการโอนข้อมูลจาก Web Server มาที่เครื่องของเรา
200 OK คือไปดึงข้อมูลมาจาก website จริงๆ
แต่พอเราไปเข้า หน้า Webpage เดิม ไม่ว่าจะด้วยการ กด F5 หรือ ปุ่ม Refresh หรือ ปุ่ม Reload
เพื่อดึงข้อมูลมาอ่าน ทาง ฺBrowser จะวิ่งไปถาม Web server ว่า หน้านั้นมีอะไรเปลียนแปลงหรือไม่
หากไม่มีการเปลียงแปลงของข้อมูลของแต่ละ Component
HTTP status code จะเท่า 304 Not Modified เป็นการบอกว่าให้ใช้ข้อมูลเก่าที่เก็บเคยเก็บไว้ในเครื่องของเรา ขึ้นมาแสดงแทน การไปเอามาจาก Web Server
เพื่อดึงข้อมูลมาอ่าน ทาง ฺBrowser จะวิ่งไปถาม Web server ว่า หน้านั้นมีอะไรเปลียนแปลงหรือไม่
หากไม่มีการเปลียงแปลงของข้อมูลของแต่ละ Component
HTTP status code จะเท่า 304 Not Modified เป็นการบอกว่าให้ใช้ข้อมูลเก่าที่เก็บเคยเก็บไว้ในเครื่องของเรา ขึ้นมาแสดงแทน การไปเอามาจาก Web Server
จากรูปข้างล่างจะแสดงให้เห็นว่า ถ้าเรากด F5 เพื่อ Page เดิมหน้านี้ ต้องไปดึง component มาทั้งหมด 100 ตัว และใช้เหลือแค่ traffic 388 KB ( น้อยกว่าเดิม 10 เท่า) ในการโอนข้อมูลจาก Web Server มาที่เครื่องของเรา เพราะ component ส่วนใหญ่ดึงจากที่เคยเก็บไว้ในเครื่องของเรามาแสดงแทน
จะเห็นได้ว่าประโยชน์คือ ทำการแสดงผลได้ไวขึ้นมาก และ ใช้ Traffic น้อยกว่าเดิม
แต่ก็อาจมีข้อเสียคือ บางที่เราจะได้ข้อมูลที่ไม่ update มาอ่าน เพราะว่าบางครั้ง Web Server มีการ update ข้อมูลใหม่ไปแล้ว แต่ Web Browser ยังใช้ ข้อมูล เก่าๆ ที่เก็บไว้ในเครื่องของเราอยู่
แต่ก็อาจมีข้อเสียคือ บางที่เราจะได้ข้อมูลที่ไม่ update มาอ่าน เพราะว่าบางครั้ง Web Server มีการ update ข้อมูลใหม่ไปแล้ว แต่ Web Browser ยังใช้ ข้อมูล เก่าๆ ที่เก็บไว้ในเครื่องของเราอยู่
จากที่กล่าวมา ถ้าต้องใส่บังคับให้ browser ไปดึงข้อมูลใหม่จาก Web Server มาแสดง เราต้องทำงานสั่ง Force Reload หรือสั่ง Clear Browser Cache ซึ่งแต่ละ OS และแต่ละ ฺBrowser จะมีวิธีการแตกต่างกันไป แต่ สวนมากจะใช้ Shift + F5 หรือไม่ก็ Ctrl +F5
วิธีการ
Bypassing cache
Internet Explorer
Use one of the following:
- Hold the Ctrl key and press the F5 key.
- Hold the Ctrl key and click the "Refresh" button on the toolbar.
Google Chrome
On Windows, use one of the following:
- Hold the Ctrl key and press the F5 key.
- Hold the ⇧ Shift key and press the F5 key.
- Hold the ⇧ Shift key and click the Reload button on the navigation toolbar.
- Hold the Ctrl key and click the Reload button on the navigation toolbar.
On Mac OS X:
- Hold both the ⌘ Cmd and ⇧ Shift keys and press the R key.
On Linux:
- Hold the Ctrl key and press the F5 key.
On Windows and Linux, use one of the following:
- Hold both the Ctrl and ⇧ Shift keys and then press R.
- Hold the ⇧ Shift key and click the Reload button on the navigation toolbar.
- Hold the Ctrl key and press the F5 key.
On Mac OS X, use one of the following:
- Hold both the ⌘ Cmd and ⇧ Shift keys and then press R.
- Hold the ⇧ Shift key and click the Reload button on the navigation toolbar.
Safari
For version 4 and newer:
- Hold down the ⇧ Shift key and click the Reload toolbar button.
For version 3 and older:
- Hold down the ⌘ Cmd key and press R. This kind of "regular" reload will usually bypass the cache.
Note that Apple claims that clicking the "Reload" toolbar button has the same effect as ⌘ Cmd+R, but this is not true; frequently the button will not bypass the cache.
Opera
Use one of the following:
- Hold the Ctrl key and press the F5 key.
- Hold the ⇧ Shift key and click the Reload button on the navigation toolbar.
- Hold the Ctrl key and click the Reload button on the navigation toolbar.
- Hold the ⇧ Shift key and press the F5 key.
Konqueror
- Press F5 or click the "Reload" button on the toolbar.
Unlike other browsers, Konqueror seems to bypass its cache whenever you reload a page.
ตัวอย่างเมื่อสั่ง Shift + F5 บน Google Chrome จะได้ HTTP Status 200 OK ที่สั่งให้ ดูดข้อมูลทั้งหมดจาก Web Server ใหม่แทนที่จะใช้ข้อมูลเก่าในเครื่อง ทำให้ ต้องใช้Transfer 4.2 MB เหมือนเดิม
ส่วนพวกอุปกรณ์พกหา เช่น Tablet หรือ Smart Phone จะต้องใช้วิธีการ Clear Browser Cache แทน
Comments
Post a Comment