julienrf / play-jsmessages

Library to compute localized messages of your Play application on client side

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make the js file(s) cacheable

francisdb opened this issue · comments

Currently the language is not in the .js file name so it can not be cached by the browser. If a user picks a different language the wrong translations would be shown.

Also the subset filtering is done each time which is suboptimal.

Would it not be better to have this plugin as an asset generator?

You can freely name the .js file to your convenience, eventually with the language in it. You just need a matching route in Play.

How would you do to cache subsets? They are totally dynamic and there is no way we could save all possible subset combinations...

I'm using this plugin as an asset generator for embedded web app. To achieve that, I'm doing a curl to the correct inside inside my grunt build. It means I need to have a local server running during the build of course.

Currently the language is not in the .js file name so it can not be cached by the browser. If a user picks a different language the wrong translations would be shown.

If you set the Vary response header to Accept-Language it should work. In case you retrieve the user’s lang from a cookie you have to manually deal with caching.

Also the subset filtering is done each time which is suboptimal.

You are right, I will try to find a fix for that in 1.6.0.

Would it not be better to have this plugin as an asset generator?

I totally agree. It is currently needing a play application instance to retrieve the messages, but maybe I could get rid of this dependency by re-implementing the messages file parsing process. I will think of this for a 2.0 version ^^

thanks for the Vary pointer, shall I split up this ticket?

Yes, that’s a good idea.

see #24 and #25
For my part this ticket can be closed as #24 would be the fix I'm looking for