I built a Magento and Wordpress module that displays popup. Some user preferences (such as if user already seen particular popup, how many times, etc.) is stored inside single cookie as array using serialize function. The module inserts into page head javascript.
<script type="text/javascript" src="http://www.thesamepageurl.com/js/modulescript.js"></script>
modulescript.js then makes ajax call to php script within the same site and appends response to html body. This php script checks the user cookie and depends on the cookie value it prints different popup content so response could be different every time.
The issue is that in some cases the entire html is cached on server side (using varnish cache or other service). I am not sure why, but even ajax call response was cached and therefore it showed popup also to users who closed it or it never showed popup because when some user closed it the don't show again was cached. To prevent that I added just some dummy POST parameter. When POST method is used, it is not cached any more.
jQuery.ajax({
type: "POST",
url: urlAction,
data:'justsomething=1',
success: function(response){
jQuery("body").append(response);
}
});
Question: Is that a safe way, will using POST ajax request within javascript prevent entire page to be cached (the page where javascript is located) or it will prevent caching just for url that is called with ajax? I don't want to prevent entire site to be cached.