Hi All,

I want to execute an ajax request on page load in D8. (intention to execute some process on page load which I have done using hook_boot in D7, Now I am trying to achieve in Drupal 8.7.6)

I have used event subscriber (refered https://www.qed42.com/blog/porting-hookinit-drupal8). I have added mymodule.libraries.yml file where I have mentioned about JS file, I have included JS file via hook_preprocess hook in mymodule.module file. 

When I enabled the module, I see JS file includes and AJAX works! but whenever I cleared the cache, JS file automatically gets removed from the list. I don't understand this behavior in D8

Any help would be appreciated !