React Native app to load data on startup for offline - reactjs

I want to build an app that would load all the data on first startup so app can be used offline. I also want to refresh the data periodically.
Does anyone have any experience designing that kind of application? I thought of using Firebase/AWS appsync but they don't load the data on startup. They cache the data once you load the page.
The data i have is from wordpress custom posts as well as some documents, images etc. How can I create a functionality to load the data on startup and keep it sync with the server.
Any link to example opensource/github/npm project would be helpful.
Thanks.

You could use that pattern,
start by loading your content using a hook, display a loading screen. Once content has loaded, just display the app.
Therefore you can rely on some cache, this is working pretty well with apollo client JS or things like https://github.com/tannerlinsley/react-query
This article can help your for your app start:
https://medium.com/javascript-in-plain-english/how-to-handle-and-design-the-startup-of-a-react-application-da779f3727e5

Related

How to save server rendered page to a custom static folder for later use in next.js

I'm creating a real estate website.
I'm using Next.Js as framework for react.
To optimise my system, I want to create a system such that:-
On first request of main page from client side, server should serve some basic data and redux, then using redux, I want to call api, recieve data and further render some same kind components on client side. Then I want to attach a functionality to the components such that, on click it checks the requested page on a custom static folder, if it is available then serve it statically to client, if not then rendered the page on server by taking data stored in redux and copy the static version of page to custom static folder and serve to client. I also want to make a function which continuosly checks on the static files expiry and update.
Problem is I'm unable to achieve the functionality of storing chunks of page statically on a custom folder, and creating check function for it on Next.Js
-------->>>>>>>>>>>>
Attaching rough image of system.
Rough Image of system
-------->>>>>>>>>>>>>
Any help or idea will be appreciated.

Split React Single page app into several Single Page Apps for faster loading?

This may sound weird at first but please read until the end. Generally Single Page Applications
(SPAs) consists of a single index.html and several JS scripts and routing is handled via Javascript with libraries like React Router, so the first load is slow because you are loading the entire application. So with the advent of Progressive Web Apps and Service Workers would not be better to split your Single Page Application into several SPAs for faster loading? Auth state and other shared state could be stored in Local Storage like for example Firebase does it. What are the issues with this approach?
As a comment from Sam already mentioned you should use code splitting to speed up the loading of your application.
You can start off by code splitting your app by the routes and build up from there.
Try using React.Suspense and React.lazy it should be a fairly quick process and you will see immediate results. Monitor the 'Network' tab in the dev tools and you will see different chunks loaded as you navigate your application.

Why is React Js called as Single Page Application

Hello guys i am new to React Js i often hear and see posts regarding react is single page app but never understood what is SPA and many say that it doesn't reload the pages but i didn't understood why so could you guys please explain me with simple examples.
A Single Page Application is a web application or website that interacts with the web browser by dynamically rewriting the current web page with new data from the web server, instead of the default method of the browser loading entire new pages.
This means that the URL of your website will not change completely (page will not reload), instead it will keep getting content and rewriting the DOM with it instead of loading a new page.
The goal is faster transitions that make the website feel more like a native app
Example: Netflix
This is the dashboard, and when we click on any movie, it changes to /watch and the content is rewritten.
In Technical Terms:
When building your react-app, you can see that there is only one
App.js from where your entire web-app is loaded in fragments and
components. This behaviour of rendering components and pages on a single page and changing the DOM( is a single page behaviour and hence the name), instead of loading a new page with new content, this makes it feel like a single application.
As mentioned in Glossary of React Terms:
A single-page application is an application that loads a single HTML page and all the necessary assets (such as JavaScript and CSS) required for the application to run. Any interactions with the page or subsequent pages do not require a round trip to the server which means the page is not reloaded.
And about "Why is React Js called as Single Page Application":
Though you may build a single-page application in React, it is not a requirement. React can also be used for enhancing small parts of existing websites with additional interactivity. Code written in React can coexist peacefully with markup rendered on the server by something like PHP, or with other client-side libraries. In fact, this is exactly how React is being used at Facebook.
A single page application has one single page e.g. www.google.ch. It is exactly one HTML file (with all its required dependencies) loaded into the browser. You'd navigate between paragraphs only using hash-router, but never ever visit another page like www.google.ch/maps (that would then be www.google.ch/#maps, which references / -> index.html) (tho google may not be the best example, it is more about URIs).
ReactJS is an open source JS library for building UI and used for SPA, and it manages the views of web apps. Reactjs can help you to modify your data without reloading of a page. It is a popular library in the market trend because of its scalability & fast performance.
Single Page applications are different from multiple page apps that we see everywhere because the SPA doesn't move into new pages; instead, it will load the pages inline within the same page.
In traditional websites, when we go from one page to another, the whole site is loaded. e.g - if you go from "www.example.com/hi" to "www.example.com/hello" the whole website is reloaded. No matter how much portion of the website is really changed. Let's say, the website has "Sidebar, logo, menu" on both of its pages, then the full reload doesn't make any sense. This takes too much time and decreases the performance.
Single Page Applications, as the name suggests, have only one single page that is loaded the first time you open the website. After this, no matter where you click, it is not gonna refresh the website fully.
browser reload button
The loading icon of the browser doesn't load when we move from one page to another on SPA site, as it does on the traditional websites.
Cons- SPA sites are great for UI UX but they are not the best when it comes to Search Engine Optimisation, it creates problems with rankings.

caching app shell in a React PWA with Server-Side rendering

So lets say you have a React-based mobile web app, that takes advantage of server-side rendering for the initial view ( for speed + SEO reasons ). There is no "index.html" file - the index file is dynamically built server-side and returned in the initial response.
Now lets say you want to add PWA functionality to that app. You hook up a service worker to cache assets, etc.
One of the core tenants of PWA's is that they provide an offline experience. Say we just want to show a refresh page, "You're offline, click here to refresh", when the service worker detects the user is offline.
Online examples provided by google talk about using an App Shell -- a static HTML file, which can be cached by the service worker on initial visit, and which will be the "shell" your react app lives inside. This shell ties in to showing an "offline" view.
How does this work with server-side rendering, where there is no "shell" html file, and each route can potentially return a different index.html file?
Any demos or examples of this functionality in the wild?
Any demos or examples of this functionality in the wild?
Yes!
Take a look at https://github.com/GoogleChrome/sw-precache/tree/master/app-shell-demo, which uses the dynamicUrlToDepndencies option in sw-precache to define which underlying resources are used to server-render the App Shell HTML.
The service worker it generates will take care of updating the App Shell HTML whenever any of the resources it depends on changes.
In this model the service worker will return the same App Shell HTML document for all navigation requests, so it assumes that the App Shell HTML is generic enough to then be populated at runtime with the dynamic content that's associated with the actual URL via your standard client-side routing logic.

reactjs in browser(local) or on server side?

I'm confused
it seems there is 2 way to run reactjs projects
1. in browser between html and script tags
2. not between html and script tags(it runs on browser) but it's different
I'm confused. explain it to me plz
React is a technology that is rendering custom web components into the browser, when you have a view, let's say dashboard composed of multiple React components, you have two ways to display that to a user:
1/ you display the html that typically contains the root React element and load an associated JavaScript script which contains all the React logic, then fetch the required data of that dashboard, so it will render all your graphs and stuff.
2/ when the user request that specific page, your server application already knows which data are required to render the initial view, so it will compute in advance how the page looks like and send a final first version to the user, it is called server-side rendering. From there obviously the page can be dynamically modified by local JavaScript running in browser afterwards, based on user interaction.
Both approaches have pros and cons, like testing capabilities, speed of execution, and so on... so I encourage you to read about the topic on the web, you can find tons of articles on React server-side rendering that will explain that better than me:
https://www.smashingmagazine.com/2016/03/server-side-rendering-react-node-express/
https://github.com/mhart/react-server-example

Resources