IE and caching AJAX calls in my Spring webapp

When things work fine in Chrome and Firefox but not in IE I am quick at hating MS. Really quick!

In one webapp I have a small widget that allows to decide which columns to show or hide. It does AJAX calls to get the users preferences and to save them when they are modified.

The problem in IE is that it would not get the new preferences as we moved in the webapp. It would keep the original preferences.

If you restart the browser then it would picked the new display preferences. We then configured IE to get new content on every page request and that also “fixed” the issue.

I decided to look to see what configuration I needed to add to my Spring 3.1 app to specify the caching on the AJAX request. I found this answer in Stackoverflow.

From that I basically added this xml to my servlet.xml file:

<!– caching settings for some URIs –>
<mvc:interceptors>
<bean class=”org.springframework.web.servlet.mvc.WebContentInterceptor” p:cacheSeconds=”0″ p:alwaysUseFullPath=”true” >
<property name=”cacheMappings”>
<props>
<!– don’t cache –>
<prop key=”/path/to/ajax/**”>0</prop>
</props>
</property>
</bean>
</mvc:interceptors>

I also needed to add xmlns:p=”http://www.springframework.org/schema/p&#8221; to my beans statement since I was not using the p namespace for anything else.

Advertisements

Published by

m5c

Java developper that loves photography and good coffee

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s