Greetings.

Trying to befriend Gulp and BrowserSync .
With HTML everything is fine, but there is no HTML in the project, only JS .
But it doesn’t work with JS all, switching to the script from under the server running will generate the script code (in the correct MIME) and without updating in the browser.

At one of the dozens of sites where I was looking for a solution, it was said that the update requires the <body></body> to enable the synchronization scripts.

Total 2 questions:

  1. How to force BrowserSync to quickly update scripts / styles in a browser?
  2. How to execute a script without HTML ?

The solution, in my opinion, is quite simple: wrapping scripts in markup implicitly.
Now a crutch is used in the form of a completely extra HTML file to which the script is connected.
This slightly overshadows total satisfaction with a good product.

Thank you for attention.

  • I have been working in this bundle for a long time and had to tweak a lot of things in bs , right up to routers and all this with a reactor and the like, but even the most pornographic thoughts cannot lead to at least one answer - why is this necessary? And if the browser expects html , is it able to execute js ? - user220409
  • @OlmerDale, That's why I think I need a wrapper. The script itself generates the HTML code for display. - user207618
  • Gulp 7: Auto - reloading browser: browser-sync from 4:30 to 5:40 probably your case - greybutton
  • @greybutton, nice try, but no. Simply, it is possible to insert a tracking script yourself, which does not save me at all, since it is also inserted into HTML , which I do not have. - user207618
  • What exactly opens in the browser? - Grundy

1 answer 1

It was decided to intercept the request to the scripts using middleware and wrap them in HTML (the solution is not finished with a file yet, so do not judge strictly):

 browserSync.init({ // ... middleware: function(req, res, next){ // Если это скрипт if(req.url === '/'){ res.end("<html><head><title>Browser Sync</title></head><body><script src='/" + data.js.buildName + "'></script></html>"); }else{ next(); } } // ... }); 

Thanks to @IvanPetrov for the idea in the chat.