Disable Caching completely

Hi guys,

My question is short (and hopefully simple to solve!): How can I completely disable browser-caching in my webservice realized with vaadin?

I want to completely disable caching since I’m getting problems when I try to do some PDF streaming and displaying them in my browers.

I have read about a solution for my problem for example here:


They talk about adding some headers to the web application that disable browser caching. But how do I add them to my application?

A short code snippet would be very welcome (and helpful!) (to be honest: Answers in general would be great as well :smiley: )

Thanks once again for your help guys :slight_smile:

I think I solved my problem using an own servlet and the following code:

Can anyone confirm that what I’ve done is correct?

(the meta tags are from this post http://stackoverflow.com/questions/1341089/using-meta-tags-to-turn-off-caching-in-all-browsers )

	 * This prevents caching in all browsers, which would, if allowed, cause
	 * caching problems while streaming and displaying pdfs
	protected void writeAjaxPageHtmlHeader(final BufferedWriter page,
			String title, String themeUri, HttpServletRequest request)
			throws IOException {
		super.writeAjaxPageHtmlHeader(page, title, themeUri, request);
		page.write("<meta http-equiv=\"cache-control\" content=\"max-age=0\" />");
		page.write("<meta http-equiv=\"cache-control\" content=\"no-cache\" />");
		page.write("<meta http-equiv=\"expires\" content=\"0\" />");
		page.write("<meta http-equiv=\"expires\" content=\"Tue, 01 Jan 1980 1:00:00 GMT\" />");
		page.write("<meta http-equiv=\"pragma\" content=\"no-cache\" />");

Thanks a lot

Okay this didn’t work. I checked it with “about.cache” and it still caches happily on my webservice?
Can anyone here help me?


See my response on

What you’ve done above is to simply remove caching from the initial bootstrap page. Every subsequent request is handled in other methods within AbstractApplicationServlet - which are tricky to override, as some of them are private.

If you’re dealing with Vaadin streaming, add the parameters to the DownloadStream - otherwise, a servlet filter is probably your best bet. Details on SO.




Thanks for your answer here, as well as the more detailed one on stackoverflow.

More in Detail, I’m using a Streamresource (This code basically comes from another user vaadin example who has shown how to integrate a pdf into a vaadin window):

final Embedded pdfContents = new Embedded();

StreamResource resource = new StreamResource(new PDF(doc), randomString.generateRandomString(), WebsiteFrame.getDefault().getMainWindow().getApplication());
// Set the right mime type

Before I had the cache time set on “0”, I’ve changed it now to “1000” as marked in your post.

I also tried the setParameter()-Method you’re mentioning on SO, but it doesn’t exist for a StreamResource.

Still, I think I might have solved the issue through generating a random String as title for the pdf. I read somewhere in the vaadin forums that these forces the browser to always reload the pdf and not using the cached version. As far as I have tested this, I’m not experiencing any wrong pdfs displayed through the cache (While about:cache always showed me that the cache grew while a pdf is being displayed, which indicates a new pdf has been added under a new title)

So, basically, this could mean that the new random name did the trick, or what do you think?