I like brainfuck. Far more accurate. At what point will people stop making things more confusing by trying to simplify them?? (Not you, the brainfu**ers)
Esoteric even!!!
“it is sometimes referred to as brainf***, brainfck, brainfsck, b***fuck, brainf**k, branflakes…”
Branflakes is my favorite
Thanks for the hint, didn’t know about stackblitz. And for the “!” I replaced it with “(” before the function and “)” at the end and seems to do the same thing. Again, I’am going to learn more about all this in the next days
It does, but with arguments:
(document,"script","twitter-wjs");
It’s still a zoo and has no business whatsoever in an Angular app.
I ran tests and posted them on a new thread, to avoid hijacking the OP.
@GMarcoSP I think your problem is because the script must have your page loaded when it (the script) is loaded. When you go back and enter the page again, the script (that has the id twitter-wjs) is already loaded, so it won’t be loaded again (it won’t enter if(!d.getElementById(id)){...} and create the script tag), but I presume that it should be loaded when the page is loaded (it was loaded before, but not now, because you entered the page again).
If that code has a global variable like window.SomeTwitterGlobalObject you could give a look in its API and try to access it. Let’s say it has a refresh() method to look for elements in your html and apply the changes that are applied in the first load, so you could just call:
if (!d.getElementById(id)) {
js=d.createElement(s);
js.id=id;
js.src=p+"://platform.twitter.com/widgets.js";
fjs.parentNode.insertBefore(js,fjs);
} else {
// You entered the page again, the script is already loaded
console.log('test'); //see if this is called
window.SomeTwitterGlobalObject.refresh();
}
That’s just one assumption, though. If the script must be loaded again (it doesn’t rely on a global variable), you could assign a different id to it every time the page is loaded:
(document,"script","twitter-wjs-" + (new Date()).getTime());
I think I don’t need to say that, in any of the cases above, the code is pretty, pretty bad. In the first because of the global variable (and I don’t know the variable name nor if there really is a method like refresh() or similar in it). In the second you would be loading the script every time you enter the page (and if it creates a global variable, it may do nothing). I also advise to create a more readable function (that is probably a snippet that the api provides, but I don’t like those kinds of snippets because they are almost illegible; you don’t have to care about minification because that is done in the build process)
The first thing that I advise you to do is see if there is some npm package or similar to do that so that you don’t have to load the script. If there isn’t, I think you should read their docs to see if there is some global variable with a method to reload/refresh like I stated above.
Update
The global object can be accessed with window.twttr, it doesn’t seem to have a refresh() or similar method though.
It seems more people had also similar problems embedding the twitter widgets in a SPA:
I resolved the problem thank you ! I understood your explanation and you were right, when the script is already loaded it won’be loaded again. Yesterday I’ve used some breakpoints and I’ve seen that the problem could come from script that don’t load more than one time. Well, the only thing i’ve done to resolve it was to remove the if condition like this
ionViewDidLoad() {
this.getInfos();
}
getInfos(){
(function(d,s,id){
var js: any,
fjs=d.getElementsByTagName(s)[0],
p='https';
js=d.createElement(s);
js.id=id;
js.src=p+"://platform.twitter.com/widgets.js";
fjs.parentNode.insertBefore(js,fjs);
}
(document,"script","twitter-wjs"));
}
Now it works many times. I will not work with generate codes anymore until I got more practical with Angular and Javascript !
@GMarcoSP That’s good to know 
Just have in mind that the script is loaded every time you enter the page (hopefully from the cache when loaded again).
Unfortunately I don’t know if there is a better solution, because that snippet (and others you find on the web) are made to work with static html pages, and don’t work very well with SPAs.