I'm currently learning Angular and trying to figure out a good pattern for lazyloading data and structuring code.
I'm making an responsive web application, and I would like do be able to define that some parts of the web-page are to be hidden from the view (preferably using media queries).
The data fetched for the hidden directives or views is then redundant.
The difference can be substantial from a desktop to a mobile view, and I would like the application to be as light as possible on the mobile perfomance wise and network usage wise.
What is a good approach for making a good architecture that could reprimend this issue?
What if the directive could check if it was currently visible (both within the current viewport and for example not within a hidden parent nor display: none.
I've provided an example usage of such a directive, but I would like some pointers to how this could be implemented.
The directive could take an expression that pointed to a callback function that should be fired when the component is visible and within 200px of the viewport.
Note: The following is a fictional example with no good use case.
<!-- Check if the device has some feature, for example touch, and hide content based on results -->
<div ng-show="current.device.touch">
<users lazyload="{userList: dataservice.getUsers | filter:search}" treshold="200px" placeholder="emptyUserlist">
</users>
</div>
How good/bad of an idea is this?
The dataservice is a more abstracted service that gets its data from $resource and cache containers.