How to conditionally disable client side










5















I have a server-side rendered app (with transition) and I have a 404 page that I've put in a lazy module (so I don't increase loaded Javascript size).



This is working fine, but there is some flickering when the client side takes over, which I think is due to the JS chunk loading after the main chunk has finished loading.



Given this page only contains static links and one routerLink, the client side is not needed at all and I'm wondering if there's a way to disable the client side on certain URLs



Edit: as suggested in the comments I tried to conditionally bootstrap the application. I can't use the URL as a condition because the server responds 404 on the non-existing URL (there is no redirect at this point). So the most appropriated thing to use is the TransferState which i successfully set up on server side and it generates some output just before the closing body tag.



Unfortunately I didn't find any way to properly instantiate TransferState in main.ts because it's supposed to be imported via BrowserTransferStateModule and I see no possible way to import an Angular module in the main.ts file.



I tried to instantiate it directly with the initTransferState function but it appears it's not designed to be used outside the module since i get an error :



ERROR in ./src/main.ts
Module not found: Error: Can't resolve '@angular/platform-browser/src/browser/transfer_state' in 'G:DocumentsProjetsMyappSourcesmasterfrontendsrc'


Any idea other than doing some dirty deserialization?










share|improve this question
























  • Maybe you could try not bootstrapping the app in your main.ts file, based on the url?

    – David
    Nov 13 '18 at 13:26











  • Your comment made me look into this file which I just discovered the purpose. This should work indeed, I will try it if there's no other built-in solution

    – YoukouleleY
    Nov 13 '18 at 13:47











  • I added some details in my question

    – YoukouleleY
    Nov 13 '18 at 23:02















5















I have a server-side rendered app (with transition) and I have a 404 page that I've put in a lazy module (so I don't increase loaded Javascript size).



This is working fine, but there is some flickering when the client side takes over, which I think is due to the JS chunk loading after the main chunk has finished loading.



Given this page only contains static links and one routerLink, the client side is not needed at all and I'm wondering if there's a way to disable the client side on certain URLs



Edit: as suggested in the comments I tried to conditionally bootstrap the application. I can't use the URL as a condition because the server responds 404 on the non-existing URL (there is no redirect at this point). So the most appropriated thing to use is the TransferState which i successfully set up on server side and it generates some output just before the closing body tag.



Unfortunately I didn't find any way to properly instantiate TransferState in main.ts because it's supposed to be imported via BrowserTransferStateModule and I see no possible way to import an Angular module in the main.ts file.



I tried to instantiate it directly with the initTransferState function but it appears it's not designed to be used outside the module since i get an error :



ERROR in ./src/main.ts
Module not found: Error: Can't resolve '@angular/platform-browser/src/browser/transfer_state' in 'G:DocumentsProjetsMyappSourcesmasterfrontendsrc'


Any idea other than doing some dirty deserialization?










share|improve this question
























  • Maybe you could try not bootstrapping the app in your main.ts file, based on the url?

    – David
    Nov 13 '18 at 13:26











  • Your comment made me look into this file which I just discovered the purpose. This should work indeed, I will try it if there's no other built-in solution

    – YoukouleleY
    Nov 13 '18 at 13:47











  • I added some details in my question

    – YoukouleleY
    Nov 13 '18 at 23:02













5












5








5


1






I have a server-side rendered app (with transition) and I have a 404 page that I've put in a lazy module (so I don't increase loaded Javascript size).



This is working fine, but there is some flickering when the client side takes over, which I think is due to the JS chunk loading after the main chunk has finished loading.



Given this page only contains static links and one routerLink, the client side is not needed at all and I'm wondering if there's a way to disable the client side on certain URLs



Edit: as suggested in the comments I tried to conditionally bootstrap the application. I can't use the URL as a condition because the server responds 404 on the non-existing URL (there is no redirect at this point). So the most appropriated thing to use is the TransferState which i successfully set up on server side and it generates some output just before the closing body tag.



Unfortunately I didn't find any way to properly instantiate TransferState in main.ts because it's supposed to be imported via BrowserTransferStateModule and I see no possible way to import an Angular module in the main.ts file.



I tried to instantiate it directly with the initTransferState function but it appears it's not designed to be used outside the module since i get an error :



ERROR in ./src/main.ts
Module not found: Error: Can't resolve '@angular/platform-browser/src/browser/transfer_state' in 'G:DocumentsProjetsMyappSourcesmasterfrontendsrc'


Any idea other than doing some dirty deserialization?










share|improve this question
















I have a server-side rendered app (with transition) and I have a 404 page that I've put in a lazy module (so I don't increase loaded Javascript size).



This is working fine, but there is some flickering when the client side takes over, which I think is due to the JS chunk loading after the main chunk has finished loading.



Given this page only contains static links and one routerLink, the client side is not needed at all and I'm wondering if there's a way to disable the client side on certain URLs



Edit: as suggested in the comments I tried to conditionally bootstrap the application. I can't use the URL as a condition because the server responds 404 on the non-existing URL (there is no redirect at this point). So the most appropriated thing to use is the TransferState which i successfully set up on server side and it generates some output just before the closing body tag.



Unfortunately I didn't find any way to properly instantiate TransferState in main.ts because it's supposed to be imported via BrowserTransferStateModule and I see no possible way to import an Angular module in the main.ts file.



I tried to instantiate it directly with the initTransferState function but it appears it's not designed to be used outside the module since i get an error :



ERROR in ./src/main.ts
Module not found: Error: Can't resolve '@angular/platform-browser/src/browser/transfer_state' in 'G:DocumentsProjetsMyappSourcesmasterfrontendsrc'


Any idea other than doing some dirty deserialization?







angular express angular-universal






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 14:12







YoukouleleY

















asked Nov 13 '18 at 8:55









YoukouleleYYoukouleleY

2,5791826




2,5791826












  • Maybe you could try not bootstrapping the app in your main.ts file, based on the url?

    – David
    Nov 13 '18 at 13:26











  • Your comment made me look into this file which I just discovered the purpose. This should work indeed, I will try it if there's no other built-in solution

    – YoukouleleY
    Nov 13 '18 at 13:47











  • I added some details in my question

    – YoukouleleY
    Nov 13 '18 at 23:02

















  • Maybe you could try not bootstrapping the app in your main.ts file, based on the url?

    – David
    Nov 13 '18 at 13:26











  • Your comment made me look into this file which I just discovered the purpose. This should work indeed, I will try it if there's no other built-in solution

    – YoukouleleY
    Nov 13 '18 at 13:47











  • I added some details in my question

    – YoukouleleY
    Nov 13 '18 at 23:02
















Maybe you could try not bootstrapping the app in your main.ts file, based on the url?

– David
Nov 13 '18 at 13:26





Maybe you could try not bootstrapping the app in your main.ts file, based on the url?

– David
Nov 13 '18 at 13:26













Your comment made me look into this file which I just discovered the purpose. This should work indeed, I will try it if there's no other built-in solution

– YoukouleleY
Nov 13 '18 at 13:47





Your comment made me look into this file which I just discovered the purpose. This should work indeed, I will try it if there's no other built-in solution

– YoukouleleY
Nov 13 '18 at 13:47













I added some details in my question

– YoukouleleY
Nov 13 '18 at 23:02





I added some details in my question

– YoukouleleY
Nov 13 '18 at 23:02












1 Answer
1






active

oldest

votes


















0














I think this is what you are looking for:



import Injectable, Inject, PLATFORM_ID from '@angular/core';
import isPlatformBrowser from '@angular/common';

export class MyComponent implements OnInit
constructor(@Inject(PLATFORM_ID) private platform: any)

ngOnInit()
if (isPlatformBrowser(this.platform))
// use clientside stuff








share|improve this answer























  • I want to completely disable the client, not only a component

    – YoukouleleY
    Nov 19 '18 at 8:31










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53277153%2fhow-to-conditionally-disable-client-side%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














I think this is what you are looking for:



import Injectable, Inject, PLATFORM_ID from '@angular/core';
import isPlatformBrowser from '@angular/common';

export class MyComponent implements OnInit
constructor(@Inject(PLATFORM_ID) private platform: any)

ngOnInit()
if (isPlatformBrowser(this.platform))
// use clientside stuff








share|improve this answer























  • I want to completely disable the client, not only a component

    – YoukouleleY
    Nov 19 '18 at 8:31















0














I think this is what you are looking for:



import Injectable, Inject, PLATFORM_ID from '@angular/core';
import isPlatformBrowser from '@angular/common';

export class MyComponent implements OnInit
constructor(@Inject(PLATFORM_ID) private platform: any)

ngOnInit()
if (isPlatformBrowser(this.platform))
// use clientside stuff








share|improve this answer























  • I want to completely disable the client, not only a component

    – YoukouleleY
    Nov 19 '18 at 8:31













0












0








0







I think this is what you are looking for:



import Injectable, Inject, PLATFORM_ID from '@angular/core';
import isPlatformBrowser from '@angular/common';

export class MyComponent implements OnInit
constructor(@Inject(PLATFORM_ID) private platform: any)

ngOnInit()
if (isPlatformBrowser(this.platform))
// use clientside stuff








share|improve this answer













I think this is what you are looking for:



import Injectable, Inject, PLATFORM_ID from '@angular/core';
import isPlatformBrowser from '@angular/common';

export class MyComponent implements OnInit
constructor(@Inject(PLATFORM_ID) private platform: any)

ngOnInit()
if (isPlatformBrowser(this.platform))
// use clientside stuff









share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 '18 at 7:58









Robin DijkhofRobin Dijkhof

8,84953068




8,84953068












  • I want to completely disable the client, not only a component

    – YoukouleleY
    Nov 19 '18 at 8:31

















  • I want to completely disable the client, not only a component

    – YoukouleleY
    Nov 19 '18 at 8:31
















I want to completely disable the client, not only a component

– YoukouleleY
Nov 19 '18 at 8:31





I want to completely disable the client, not only a component

– YoukouleleY
Nov 19 '18 at 8:31



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53277153%2fhow-to-conditionally-disable-client-side%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

Museum of Modern and Contemporary Art of Trento and Rovereto