javascript - Why duplicate script tags do not produce duplicate requests? -
i have simple test case (and 3 hours of googling , flu)
<!doctype html> <html lang="en-us"> <head> <meta charset="utf-8"> <title>Два внешних скрипта</title> </head> <body> <script type="text/javascript" src="http://example.com/myscript.js"></script> <script type="text/javascript" src="http://example.com/myscript.js"></script> </body> </html>
and server return following reponse headers
connection: keep-alive expires: mon, 04 dec 1999 21:29:02 gmt cache-control: no-store, no-cache, must-revalidate, max-age=0 pragma: no-cache
this code executed in chrome produces 1 request server, in opera, safari win.
is behaviour in anyway standard?
is there official documentation behaviour?
is cashe issue, cause thought still have request anyway 304 response?
disclaimer: please not suggest randomizing or avoiding issue. want learn background of issue
there 2 reasons why can happen. first content provider can set expires
heading browser not issue second request, , second how browsers handle get
requets in http, such request include script.
1. setting expires header of content
the content provider can set expires
header script cached browser first time, hence lack of second request. standard web practice speeding web pages, , expires header set host server of script. yahoo developer has article on @ add expires or cache-control header recommends adding expires header scripts , stylesheets in addition images.
2. script method idempotent
get
requests, such request include javascript on webpage safe methods according http specification. safe methods idempotent, in multiple requests yield same result single request , method used retrieve data. many browsers take advantage of property of http specification, , won't sent multiple requests idempotent methods. george cummins explained well, , article on available mozilla developer network.
Comments
Post a Comment