0

I'm currently using Angular elements to generate web components for a project and I'm having issues figuring out a way to dynamically change the script version value in a way to still work with the web component. I'm somewhat new to web components so any help is appreciated. An example of what is put in the HTML..

<webcomponent-classroom></webcomponent-classroom>
<script src="http://192.168.1.123:8080/webcomponent-classroom.js?v=13"></script>

I've tried things like this for example with no luck

<script>document.write('http://192.168.1.123:8080/webcomponent-classroom.js?v=' + Date.now() + '"><\/script>');</script>
cempro
  • 49
  • 1
  • 7
  • Your first code snippet is fine. Check the Browser Console for 404 errors. Or the error is in that JS file... post the contents. – Danny '365CSI' Engelman Apr 13 '21 at 15:07
  • Note; if you want to learn Web Components; I suggest you start with vanilla JavaScript, No libraries, No frameworks. That way you learn the core technology, not the sugar all those tools provide (and make you never learn the core technology) Its like making tomato soup.. start with raw ingredients.. don't start with a Campbell package – Danny '365CSI' Engelman Apr 13 '21 at 15:11
  • So their is no error the top snippet does work, but im looking for a way to dynamically change that version without manually having to every time i rebuild for example, and so that users are always getting the latest. – cempro Apr 13 '21 at 15:13
  • https://www.google.com/search?q=javascript+cache+busting+techniques – Danny '365CSI' Engelman Apr 13 '21 at 15:15
  • Thanks for advice i've started down the road of web components and you're right learning the fundamentals first would definitely help. This question is more updating that script version – cempro Apr 13 '21 at 15:15
  • The second snippet i have does generate a script file with a date number attached which is the desired outcome, but idk if its the timing or what but that script change causes the web component not to pick it up for some reason. – cempro Apr 13 '21 at 15:17
  • Without the content of that JS file we can only wild guess... – Danny '365CSI' Engelman Apr 13 '21 at 15:23
  • Its just a bunch on minified JS that angular elements bundles up, main.js, runtime.js polyfills.js etc. I don't think its an issue of whats in that fine but when the web component is trying to access that js file, its like the document write creates the script to late or something. – cempro Apr 13 '21 at 15:31
  • Start **without** WebComponent (or any code) Make it work with just a ``console.log()`` in a JS file. If that works the problem is IN your JS file – Danny '365CSI' Engelman Apr 13 '21 at 15:35
  • I'll give that a shot in a bit thanks for the advice maybe a bit before i get back. – cempro Apr 13 '21 at 15:36

0 Answers0