Possible to cache JSON to increase performance / load time?

后端 未结 6 1161
我寻月下人不归
我寻月下人不归 2020-12-13 11:14

I\'m using a JSON file to autopopulate a drop down list. It\'s by no means massive (3000 lines and growing) but the time taken to refresh the page is becoming very noticeab

6条回答
  •  盖世英雄少女心
    2020-12-13 12:04

    Here is a simple hack:

    Create a call to a php file as GET request with parameter "bla-bla.html" or "bla-bla.css"... well you know, it makes browser think it is not a php, but rather "html" or "css". And browser will cache it.

    To verify that the trick is working - go to the "network" tab of the browser dev panel and you will see column "type" there along with "transferred" - instead of having php there and actual size, you will find "html" and "(cached)"

    This is also good to know when you passing parameters like "blah-blak.html" to the php file and expect it will not be cached. Well, it will be cached.

    Tested on FireFox Quantum 57.0.1 (Mac 64bit)

    P.S.

    Chrome 63 on Mac is capable of recognising real file type in this situation. So it cannot be fooled.

提交回复
热议问题