Preferable Tactics For Single Page Application
Single page application also uses JavaScript to load other content when users are navigating to other parts of the single-page application. These are often called views rather than pages. This technique allows us to load views without the browser doing a full reload and allows us to use custom transitions between the different parts of the application. Single-page apps might use an architectural pattern called the app shell model, where the shared parts of the UI in code, like menus, headers, footers, and so on, are loaded when initially loading the single-page application. And the different views are dynamically loaded into this shell, reducing the amount of data needed to send over the network. Okay.
So what do we need to look out for when building single-page apps? – I think it is time to look at our sample app, test it, and then improve it where we see potential. Our example application is an e-commerce web app You can browse different product categories, learn more about a specific product, and you can put it into your cart. It also uses the user’s location to display prices in the local currency. When we run the mobile-friendly test, there is a bit of an issue. The main content doesn’t show up. Time to investigate this.
In the JavaScript console messages, we can see that there is a problem with our code. We are incorrectly using an unsupported feature. That’s an important point here. Sometimes, we do forget that code doesn’t always take the happy path. In our example, we assume that we always get the user location. But we forgot to deal with situations where that isn’t available. It’s important to make sure that you cover all code paths to avoid these scenarios. Googlebot, for example, declines the request for the geolocation. I also noticed something else when using the shop. It does not change the URL when navigating between different views. But as Googlebot uses URLs to locate these different “pages”, or views in our case, this would mean that Googlebot would only see our homepage and nothing else.
To fix this, we can use the history API and proper link markup with href attributes to expose the other views as URLs within the links. It’s also a good idea to take a look at the titles and meta descriptions for our different views. Right now, all views have the same generic title and meta description. This isn’t really helpful when people are searching for the one specific product or a specific category in our shop. With a little bit of extra JavaScript, we can fix this quite quickly. This will look much better in the search results. A very common problem is the way that single-page applications are dealing with error scenarios, such as invalid URLs. In our example, the application displays an error message, but the server reports an HTTP 200. That is a bit of an issue, specifically, in single-page applications because the server doesn’t really do the error handling anymore. Usually, the server serves the web app in all cases, and then the JavaScript and the browser decides if it wants to display an error.
But HTTP status codes do help Googlebot and browsers decide how to deal with the response. So we should fix this. Here’s the JavaScript that deals with the error situation. It reads the URL and fetches the data, and if that fails, it displays an error message. But we can’t just tell JavaScript to report a different status code because this status code can’t be changed once the server sent it. What we can do, though, is to configure our server to respond with an error code for a specific URL, like /not-found gives a 404 and/maintenance gives a 500, and so on.
When we do that, we can use JavaScript to redirect to the designated error URL. This signals to the browsers and Googlebot that the page is just a redirect to another URL, and this URL is an actual error. Alright, now our web shop can be crawled and indexed, gives useful product information and search result pages, and behaves properly when there is an error.
esciencejournals
November 27, 2024experience and quality thank you.esciencejournals
escientificreviews
November 28, 2024experience and quality thank you.escientificreviews
escientificres
November 28, 2024experience and quality thank you.escientificres
emedicalhub
November 29, 2024experience and quality thank you.emedicalhub
scholarlymed
November 29, 2024experience and quality thank you.scholarlymed
theresearchpub
November 29, 2024experience and quality thank you.theresearchpub
eclinmed
November 29, 2024experience and quality thank you.eclinmed
epharmajournal
November 29, 2024experience and quality thank you.epharmajournal
pulsusjournal
November 29, 2024experience and quality thank you.pulsusjournal
biochemjournals
November 29, 2024experience and quality thank you.biochemjournals
oajournalres
November 29, 2024experience and quality thank you.oajournalres
accademiaestetica
December 3, 2024experience and quality thank you.accademiaestetica
irisgioiellicomprooro
December 3, 2024experience and quality thank you.irisgioiellicomprooro
bcn
December 3, 2024experience and quality thank you.bcn
passeritartufi
December 3, 2024experience and quality thank you.passeritartufi
realizzazione-giardini
December 3, 2024experience and quality thank you.realizzazione-giardini
leragazzedifirenze
December 3, 2024experience and quality thank you.leragazzedifirenze
res-botanica
December 3, 2024experience and quality thank you.res-botanica
ittoscana
December 3, 2024experience and quality thank you.ittoscana
anti-flood-barriers
December 3, 2024experience and quality thank you.anti-flood-barriers
bb-one
December 8, 2024experience and quality thank you.bb-one
orologeriatoscana
December 8, 2024experience and quality thank you.orologeriatoscana
sicc
December 8, 2024experience and quality thank you.sicc
cavalierinternational
December 9, 2024experience and quality thank you.cavalierinternational
bacosport
December 9, 2024experience and quality thank you.bacosport
ciaociao
December 9, 2024experience and quality thank you.ciaociao
digitaltechsquad
December 17, 2024experience and quality thank you.digitaltechsquad
daliamohamed
December 17, 2024experience and quality thank you.daliamohamed
sshoreendo
December 19, 2024experience and quality thank you.sshoreendo
stevesmeatsfreeport
December 19, 2024experience and quality thank you.stevesmeatsfreeport
straightlineconst
December 19, 2024experience and quality thank you.straightlineconst