Restrict SSR to paths in the sitemap

Because Angular SSR is not very efficient, after discussion with
the Google Scholar team we realized a compromise would be to only
use SSR for pages in the DSpace sitemap (and the home page).

(cherry picked from commit 5b3b3bfb9c)
This commit is contained in:
Alan Orth
2024-11-22 12:29:32 +03:00
committed by github-actions[bot]
parent ad74ce6049
commit 026703d170
6 changed files with 11 additions and 1 deletions

View File

@@ -23,6 +23,8 @@ ssr:
# Determining which styles are critical is a relatively expensive operation; this option is
# disabled (false) by default to boost server performance at the expense of loading smoothness.
inlineCriticalCss: false
# Path prefixes to enable SSR for. By default these are limited to paths of primary DSpace objects.
paths: [ '/home', '/items/', '/entities/', '/collections/', '/communities/', '/bitstream/', '/bitstreams/', '/handle/' ]
# The REST API server settings
# NOTE: these settings define which (publicly available) REST API to use. They are usually

View File

@@ -218,7 +218,7 @@ export function app() {
* The callback function to serve server side angular
*/
function ngApp(req, res, next) {
if (environment.ssr.enabled) {
if (environment.ssr.enabled && req.method === 'GET' && (req.path === '/' || environment.ssr.paths.some(pathPrefix => req.path.startsWith(pathPrefix)))) {
// Render the page to user via SSR (server side rendering)
serverSideRender(req, res, next);
} else {

View File

@@ -20,4 +20,9 @@ export interface SSRConfig extends Config {
* For improved SSR performance, DSpace defaults this to false (disabled).
*/
inlineCriticalCss: boolean;
/**
* Paths to enable SSR for. Defaults to the home page and paths in the sitemap.
*/
paths: Array<string>;
}

View File

@@ -8,5 +8,6 @@ export const environment: Partial<BuildConfig> = {
enabled: true,
enablePerformanceProfiler: false,
inlineCriticalCss: false,
paths: [ '/home', '/items/', '/entities/', '/collections/', '/communities/', '/bitstream/', '/bitstreams/', '/handle/' ],
},
};

View File

@@ -12,6 +12,7 @@ export const environment: BuildConfig = {
enabled: true,
enablePerformanceProfiler: false,
inlineCriticalCss: false,
paths: [ '/home', '/items/', '/entities/', '/collections/', '/communities/', '/bitstream/', '/bitstreams/', '/handle/' ],
},
// Angular express server settings.

View File

@@ -13,6 +13,7 @@ export const environment: Partial<BuildConfig> = {
enabled: false,
enablePerformanceProfiler: false,
inlineCriticalCss: false,
paths: [ '/home', '/items/', '/entities/', '/collections/', '/communities/', '/bitstream/', '/bitstreams/', '/handle/' ],
},
};