Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Initialize Imported Scripts #106

Open
1 of 3 tasks
JackForbes opened this issue Sep 29, 2017 · 4 comments
Open
1 of 3 tasks

How to Initialize Imported Scripts #106

JackForbes opened this issue Sep 29, 2017 · 4 comments
Labels

Comments

@JackForbes
Copy link

  • I'm submitting a bug report
  • I'm submitting a feature request
  • 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();

@krishnappan95
Copy link

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.

@Garito
Copy link

Garito commented Nov 29, 2017

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

@goldhand
Copy link
Owner

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

@p-rk
Copy link

p-rk commented Dec 10, 2018

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants