sw-precache-webpack-plugin icon indicating copy to clipboard operation
sw-precache-webpack-plugin copied to clipboard

How to Initialize Imported Scripts

Open JackForbes opened this issue 8 years ago • 4 comments

  • [ ] I'm submitting a bug report
  • [ ] I'm submitting a feature request
  • [x] I'm submitting a support request

webpack version: 1.14

sw-precache-webpack-plugin version: 0.11.4

Question How can I go about initializing an imported script? Specifically, I'm trying to implement Offline Google Analytics.

There's documentation for importing the script but I'm not sure how to initialize afterward: importScripts('path/to/offline-google-analytics-import.js'); goog.offlineGoogleAnalytics.initialize();

JackForbes avatar Sep 29 '17 15:09 JackForbes

I also like to know how to initialize the imported Scripts? I am trying to use sw-offline-google-analytics to store analytics in offline mode and send it after coming online.

krishnappan95 avatar Oct 30 '17 14:10 krishnappan95

Any help on this so far? I have the same issue here...

Garito avatar Nov 29 '17 16:11 Garito

Can you not initialize the script from the file that is being imported?

goldhand avatar Apr 15 '18 20:04 goldhand

@Garito @JackForbes @krishnappan95 you can do something like this create a js file (example: offline-analytics.js) in your project then add below

importScripts('https://storage.googleapis.com/workbox-cdn/releases/3.6.1/workbox-sw.js');
workbox.googleAnalytics.initialize();

then you in your config include the file

    new SWPrecacheWebpackPlugin({
      cacheId: 'rama',
      filename: 'sw.js',
      minify: true,
      importScripts: [
        'offline-analytics.js'
      ]
   })

Just make sure that you able to serve the offline-analytics.js file from your project

p-rk avatar Dec 10 '18 05:12 p-rk