vuejs / vue-hackernews-2.0

HackerNews clone built with Vue 2.0, vue-router & vuex, with server-side rendering
MIT License
10.96k stars 2.15k forks source link

3rd party fails to load on second pageload #356

Open Ornhoj opened 5 years ago

Ornhoj commented 5 years ago

Hi @yyx990803 Some service integrations require an embedded script inside the vue instance. This is per default not allowed, but with packages like vue-script2 it is possible - however.

Integrating a third party script inside the vue instance will only allow it to load on the first page load both SSR loaded and CSR. The only way I have found to hack this issue is to apply some information about the current page contains a "unsupported" script and force a SSR by window.location.replace in the beforeRouteUpdate navigation guard.

Is there a way to implement third party scripts provided by some companies, that will load every time?

I have used the following as a base for testing in both in Vue CLI and Vue-Hackernews 2.0 boilerplate.

<div data-widget-url="https://septima.dk/widget/config/layer.json"></div>
<script src="https://widgetconfig.septima.dk/widgetconfig.js"></script>

This perticular case can be hacked but the issue still prevails if only a script-tag is provided which has to be placed in context.

I personally see this as a missing part of Vue if my case is unsupported.

Cheers