Introduction
Despite the increasing processing power of today's devices, the performance and efficiency of web portals must be taken into account in the current paradigm, as they run not only on desktop computers, but also on mobile devices powered by batteries. Additionally, users increasingly expect web solutions to perform as well as native solutions.
Performance Improvement
Web pages are composed of various elements, from images to complementary files invisible to the user (software libraries, CSS files, etc.). When browsing a portal, it is very common for a web page to need resources already previously obtained for the previous page – let's think about the portal logo, for example. It turns out that this type of resource is often requested by the portal multiple times. It is easy to identify the consequences of this type of behavior: increased load on servers (directly proportional to their maintenance cost), page load time, network resource consumption, power consumption, etc.
Fortunately, these situations are avoidable with a Service Worker (SW). It is a small program, run by the browser in parallel with the portal, which acts as a layer between this and the Web. Knowing the features that the portal requests and gets from the server, SW enables the creation of local caches to improve performance and efficiency, or even implement offline utilization. To address the problem under analysis, you can:
- Constitute a list of resource URLs used by multiple pages, which are immediately cached or
- Define rules for caching certain types of resources after they are obtained only once (for example: store all videos).
Later, when needed, the SW serves them to the portal, avoiding repeated requests. Note that these should be features with low expected modification rate - such as logos and style files.
Conclusion
This solution, not being a time-consuming implementation, can easily be used in several portals with few code modifications. It is therefore a tool to be taken into account in the development of the best web solutions. This is one of the ways in which attention to detail contributes to the creation of better software.