TL;DR Look-ahead requests (prefetch, Prefetch) may jump not only to css but also to other URLs. For a specific endpoint
--I want to know more accurately the number of GET requests caused by user actions ――Since it is a relatively heavy process, I do not want to process unnecessary requests as much as possible
If you have the above needs, you should take prefetch measures.
While developing a Web system, I thought about the cause because an unintended GET request came into the log for the test server. After investigating, it seems that the browser may skip the GET request as a look-ahead (prefetch) process when entering something in the browser bar, and since a unique value is set in the header for that request, each browser The detection process was implemented to support the specifications of.
Chrome(Chromium)
Purpose: prefetch
https://www.chromestatus.com/feature/6247959677108224
https://bugs.chromium.org/p/chromium/issues/detail?id=86175#c65
Firefox
X-Moz: Prefetch
https://developer.mozilla.org/ja/docs/Web/HTTP/Link_prefetching_FAQ
Safari
X-Purpose: preview
import org.apache.commons.lang3.StringUtils;
import javax.servlet.http.HttpServletRequest;
public static boolean isPrefetchRequest(HttpServletRequest request) {
return StringUtils.equalsAny(request.getHeader("purpose"), "Prefetch", "prefetch") ||
StringUtils.equalsAny(request.getHeader("X-moz"), "Prefetch", "prefetch") ||
StringUtils.equalsAny(request.getHeader("X-Purpose"), "Preview", "preview");
}
――Since the specifications are not decided by a light examination, follow-up will be done on the assumption that changes will be made. --The information provided is as of the time of writing.
Recommended Posts