A Swift framework for caching entire web pages for offline browsing and faster loading on iOS.
Mattress is a Swift framework for iOS that enables offline caching of entire web pages. It creates a separate disk cache that works with the standard NSURLCache system, allowing developers to pre-cache web content for faster loading and make it available when the device has no internet connection. The framework intercepts web requests and serves cached content when appropriate.
iOS developers building applications that need to display web content reliably in offline scenarios or require faster web page loading through pre-caching. This is particularly useful for news readers, content-heavy apps, or any application that embeds web views.
Developers choose Mattress because it provides a specialized caching layer specifically designed for complete web pages, going beyond standard URL caching. It offers simple integration with existing iOS networking code and handles the complexity of caching dynamic web content with JavaScript and images.
iOS Offline Caching for Web Content
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Mattress stores entire web pages, including HTML, CSS, JavaScript, and images, enabling full offline browsing as demonstrated in the example where pages load without internet.
Supports caching web pages in the background for improved performance, which is highlighted as a key feature for faster loading in content-heavy apps.
Offers straightforward methods like `diskCacheURL:loadedHandler:` for caching, making integration easy with minimal code, as shown in the usage snippets.
Works alongside the standard iOS caching system, allowing developers to use familiar patterns while adding offline capabilities, as it sets the shared cache in the app delegate.
Explicitly incompatible with WKWebView, the modern iOS web view, limiting its use in newer apps that rely on WKWebView's better performance and features.
Caching operations occur on the main thread, potentially causing UI lag, as warned in the considerations section for active foreground caching.
Requires manual integration of both Mattress and CommonCrypto frameworks, adding overhead to the build process, especially with Carthage as recommended.