Skip to content

Commit 5b3b3bf

Browse files
committed
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).
1 parent c5f07da commit 5b3b3bf

File tree

6 files changed

+11
-1
lines changed

6 files changed

+11
-1
lines changed

config/config.example.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ ssr:
2323
# Determining which styles are critical is a relatively expensive operation; this option is
2424
# disabled (false) by default to boost server performance at the expense of loading smoothness.
2525
inlineCriticalCss: false
26+
# Path prefixes to enable SSR for. By default these are limited to paths of primary DSpace objects.
27+
paths: [ '/home', '/items/', '/entities/', '/collections/', '/communities/', '/bitstream/', '/bitstreams/', '/handle/' ]
2628

2729
# The REST API server settings
2830
# NOTE: these settings define which (publicly available) REST API to use. They are usually

server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ export function app() {
218218
* The callback function to serve server side angular
219219
*/
220220
function ngApp(req, res, next) {
221-
if (environment.ssr.enabled) {
221+
if (environment.ssr.enabled && req.method === 'GET' && (req.path === '/' || environment.ssr.paths.some(pathPrefix => req.path.startsWith(pathPrefix)))) {
222222
// Render the page to user via SSR (server side rendering)
223223
serverSideRender(req, res, next);
224224
} else {

src/config/ssr-config.interface.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@ export interface SSRConfig extends Config {
2020
* For improved SSR performance, DSpace defaults this to false (disabled).
2121
*/
2222
inlineCriticalCss: boolean;
23+
24+
/**
25+
* Paths to enable SSR for. Defaults to the home page and paths in the sitemap.
26+
*/
27+
paths: Array<string>;
2328
}

src/environments/environment.production.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ export const environment: Partial<BuildConfig> = {
88
enabled: true,
99
enablePerformanceProfiler: false,
1010
inlineCriticalCss: false,
11+
paths: [ '/home', '/items/', '/entities/', '/collections/', '/communities/', '/bitstream/', '/bitstreams/', '/handle/' ],
1112
},
1213
};

src/environments/environment.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const environment: BuildConfig = {
1212
enabled: true,
1313
enablePerformanceProfiler: false,
1414
inlineCriticalCss: false,
15+
paths: [ '/home', '/items/', '/entities/', '/collections/', '/communities/', '/bitstream/', '/bitstreams/', '/handle/' ],
1516
},
1617

1718
// Angular express server settings.

src/environments/environment.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const environment: Partial<BuildConfig> = {
1313
enabled: false,
1414
enablePerformanceProfiler: false,
1515
inlineCriticalCss: false,
16+
paths: [ '/home', '/items/', '/entities/', '/collections/', '/communities/', '/bitstream/', '/bitstreams/', '/handle/' ],
1617
},
1718
};
1819

0 commit comments

Comments
 (0)