7

I have a @JavaScript annotation in my application to load a .js file from the classpath.

Now I've made an update to the file and redeployed (locally), but I always get the old version back. I've tried reloading everything (ctrl+R, ctrl+F5) but that doesn't work and also I wouldn't want the users to have to do that.

A trick I used in the past (without Vaadin) was to append a request parameter with the version (e.g. ?version=1) and update that so that the URL changes. But apparently that isn't allowed for the @JavaScript annotation (Vaadin doesn't even try to load the file).

4
  • Maybe your app is using the @PreserveOnRefresh annotation on the UI object? This might prevent Vaadin from reloading any JS. Commented Jan 12, 2015 at 17:19
  • No, I'm not using @PreserveOnRefresh. Besides, I had restarted the server so that wouldn't have made a difference. I've currently just changed the filename (added _vxxx where xxx is a number) and that works.
    – herman
    Commented Jan 12, 2015 at 17:50
  • so you are saying, that even a server restart kept the "old" file? could you do a find for the file in your target-dir? could be, that it's there several times (e.g. once from your ide and once from your build tool). if both are in the classpath only one get picked up.
    – cfrick
    Commented Jan 12, 2015 at 17:54
  • well, at least now that I have renamed the file, there's no file with the old name lying around. Before the rename, I did check the file in the target folder and it had the new contents, but still I was getting the old contents in the browser.
    – herman
    Commented Jan 12, 2015 at 18:10

4 Answers 4

4

I have overcome this by utilizing the resourceCacheTime parameter of the Vaadin servlet configuration:

@VaadinServletConfiguration(ui = MyUI.class, resourceCacheTime = 0)

Although it has its limitation as described in my answer to another question here.

1

This is browser feature to localy cache JS files, nothing to do with Vaadin.

As you figure it out yourself: If you want to make sure users have latest version of JS file, you should rename JS file name to: script_buildNumber.js.

2
  • I don't agree that this has nothing to do with Vaadin: there are ways for web applications to tell the browser e.g. not to cache certain resources. I came up with the answer of renaming the file myself but that's really a hack. At least being able to add a request parameter would prevent me from having to change the actual name of the file in version control.
    – herman
    Commented Jan 13, 2015 at 13:14
  • after a restart of the container, the new file is definetly loaded fresh from disc and a CTRL-F5 reload at least in Fx in default config will pull the new file.
    – cfrick
    Commented Jan 13, 2015 at 20:50
0

Use the Chrome's incognito feature (and not use it when visiting spicy/unpleasant websites).

Just open your browser in Incognito mode https://support.google.com/chrome/answer/95464?hl=en and the browser will cache nothing.

Other browsers have this feature as well (Opera, IE, Firefox, Safari).

2
  • I wouldn't want my users to have to visit my web app in incognito mode to ensure they have the latest javascript files. Vaadin should provide a way to tell the browser not to cache them, or support adding request parameters to the name so files don't have to be physically renamed.
    – herman
    Commented Feb 4, 2015 at 10:25
  • Sure, I agree with you, I thought you need it only for development.
    – tonix
    Commented Feb 4, 2015 at 11:11
0

As I noted in my comment on the question on January 12th, renaming the file worked. This seems to be currently the only way, although it's far from ideal.

Not the answer you're looking for? Browse other questions tagged or ask your own question.