views:

573

answers:

2

I have create a skeleton Wicket project using

mvn archetype:create -DarchetypeGroupId=org.apache.wicket -DarchetypeArtifactId=wicket-archetype-quickstart -DarchetypeVersion=1.4-rc4 -DgroupId=com.mycompany -DartifactId=myproject

All the configuration/importing new project with Maven/Intellij worked fine. I proceeded to add a basic CSS file to my start page, per the following recommended way of doing it in Wicket 1.4

public class BasePage extends WebPage {
    public BasePage() {
        add(CSSPackageResource.getHeaderContribution(BasePage.class, "main.css"));
    }
}

The main.css file has been put along side BasePage.java and BasePage.html in /src/main/java. I launch the application with Start.java. The problem is when I make changes to the CSS file it is not being picked up when I relaunch Start.java. (Changes to the java and html files are being updated when I change them)

I made sure the browser cache was being cleared, and even valided the request/response in Firfox/Firebug. It seems like somewhere between Wicket's magic and the jetty instance Start.java creates the CSS file is being cached and not updated. Any ideas?

+1  A: 

I moved the css files into the /webapp directory and that seemed to solve the issue of getting Start.java to register the changes. I am doing the same for js files and images. Strangely, I have read (on multiple sites) people doing this in different ways (Although the consensus for HTML and Java classes is always to have them the same place).

Scanningcrew
A: 

I find an other solution that helps me. You can configure Wicket to add a timestamp to the request for a resource to solve the caching problem. In the init method of your application class call setAddLastModifiedTimeToResourceReferenceUrl of the recource settings.

public class MyApplication extends WebApplication {
    @Override
    protected void init() {
        getResourceSettings().setAddLastModifiedTimeToResourceReferenceUrl(true);
    }
}

Original: http://old.nabble.com/Javascript-CSS-being-cached-by-the-browser-even-when-it-has-changed.-Should-setAddLastModifiedTimeToResourceReferenceUrl%28true%29-be-the-default--td14886538.html

Arne