I store a lot of assets in the form of .jpg files, logos, etc. I use PDFRenderer heavily to create highly customized and code-conditional reports in .pdf format. My question is, what is the best way to create and store these image files, .jpg, .png, etc.? Also, are there best practices when conditionally calling them as image.source(_\theme\logo.jpg) in code that I am perhaps missing?
I believe what I’m seeing is a slight loss in resolution… I’d like to optimize the sharpness and clarity.
All the images stored as assets are loaded when the app starts, so it is not a scalable way to add many images. Plus they can be resized and their quality can decrease.
A better and scalable way is to store them in a data table, so they will be loaded only when needed, and their quality will not be affected.
The table could have one column with the image and one with the unique name.
Then you could create a server function that takes a list of image names and returns a list of media objects, and the form will call the function and assign each media object to its control.
2 Likes
In the past we’ve been told that assets are lazily loaded: Where to store rarely used Javascript/CSS? - #11 (except for html files and theme.css, for obvious reasons).
I don’t know if that’s changed since then.
I don’t know why you’d see a change in resolution quality from images stored in assets.
2 Likes
To clarify: Assets are lazily loaded when running the app; however as of the time I’m writing this:
- They are eagerly loaded when loading the Editor, so large assets can still get in your way as a developer
- Behind the scenes, they are still loaded off the disk into our cache, which can slow down app serving in extreme cases (we’ve seen apps with 100MB+ of assets before - which, ahem, violated some of our assumptions about how fast we can get app source code from one server to another on the backend)
So I wouldn’t obsess about smallish assets, but once your sizes are getting large you’re probably doing yourself a favour to follow @stefano.menci’s advice.
4 Likes
Thanks for the clarification Meredydd.
Can you add a comment about what @dconnell says “I believe what I’m seeing is a slight loss in resolution”, which reminds me of this old post of mine?
I tried to reproduce the problem, and it looks like I was wrong in that front as well:
- I tried to upload a 5+MB jpg and bmp into an image from the image properties, and I got the “File Too Large” message
- I uploaded the same files without problems as asset, then added them to the image properties, and there was no loss in resolution
Is it still possible to have a loss in resolution?
Or is that old post no longer valid?