Preventing iframe caching in browser

前端 未结 13 1443
自闭症患者
自闭症患者 2020-11-29 18:03

How do you prevent Firefox and Safari from caching iframe content?

I have a simple webpage with an iframe to a page on a different site. Both the outer page and the

13条回答
  •  星月不相逢
    2020-11-29 18:28

    After trying everything else (except using a proxy for the iframe content), I found a way to prevent iframe content caching, from the same domain:

    Use .htaccess and a rewrite rule and change the iframe src attribute.

    RewriteRule test/([0-9]+)/([a-zA-Z0-9]+).html$ /test/index.php?idEntity=$1&token=$2 [QSA]

    The way I use this is that the iframe's URL end up looking this way: example.com/test/54/e3116491e90e05700880bf8b269a8cc7.html

    Where [token] is a randomly generated value. This URL prevents iframe caching since the token is never the same, and the iframe thinks it's a totally different webpage since a single refresh loads a totally different URL :

    example.com/test/54/e3116491e90e05700880bf8b269a8cc7.html
    example.com/test/54/d2cc21be7cdcb5a1f989272706de1913.html

    both lead to the same page.

    You can access your hidden url parameters with $_SERVER["QUERY_STRING"]

提交回复
热议问题