Question

i used to declare my static ressources using the following code in my Play 1.2.5 templates :

<img src="@{'/public/images/team/myTeam.png'}"/>

My problem is when the specified file is missing, the view crashes... How can i avoid this problem ? I'd prefer displaying a view with a missing image rather than no view at all !

My context : i'm using Play 1.2.5 on Google App Engine.

Was it helpful?

Solution

Although it's not a direct answer, maybe it will help you somehow.

Generally I would recommend removing public, static resources like images from the application to some CDN (I don't know Google's Engine, however fast search showed me that people does that) thanks to this you'll avoid displaying the error page. (nota bene displaying custom error page for missing files makes no sense as you don't display the image separately but with <img> tag)

Additionally CDN gives you more profits, like caching files in closer distance from the client, while fetching files from CDN in another domain, the browser doesn't send whole redundant stuff like cookies, etc. Finally you can replace the resources without need of re-deploying the application.

OTHER TIPS

<img> is a HTML tag and has an alt attribute that can be used to show instead of an image, when the image is not available. Besides, if you are working under debug mode, you probably see the error page, generated by play framework. Try switching to prod mode and inspect the results

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top