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

Some files pushed via node-spdy can not be found in browser cache #262

Open
lewispham opened this issue Jun 28, 2016 · 5 comments
Open

Some files pushed via node-spdy can not be found in browser cache #262

lewispham opened this issue Jun 28, 2016 · 5 comments

Comments

@lewispham
Copy link

lewispham commented Jun 28, 2016

I've tried to serve some files via http2. Here is my code.

Server

if (req.url === '/') {
  let files = [
    'avatar.png',
    'avatar180.png',
    'bcrypt.js',
    'favicon-32x32.png',
    'language.js',
    'logo.png',
    'logo320.png',
    'main.css',
    'main.htm',
    'privacy.htm',
    'svw.js',
    'sw.js',
    'terms.htm',
    'xregexp.js'
  ];
  for (let name of files) {
    // all those files are stored in memory.
    // `CACHE` object is their container
    let file = CACHE[name];
    if (file) {
      let push = res.push('/app/' + name, {
        response: file.headers
      });
      push.on('error', er => console.log(er));
      push.end(file.content);
    }
  }
  let file = CACHE['main.htm'];
  res.writeHead(200, file.headers);
  res.end(file.content);
}

Client

[
  'avatar.png',
  'avatar180.png',
  'bcrypt.js',
  'favicon-32x32.png',
  'language.js',
  'logo.png',
  'logo320.png',
  'main.css',
  'main.htm',
  'privacy.htm',
  'svw.js',
  'sw.js',
  'terms.htm',
  'xregexp.js'
].forEach(name => fetch('/app/' + name));

Result
untitled

As you can see from the above result, 6 out of 14 files are not fetched from cache. And I still can't figure out the reason behind this strange behaviour.

P/s. This test is run on Chrome v51.0.2704.106 m (64-bit), Node.js v6.2.2 and node-spdy v3.3.3

@lewispham lewispham changed the title Some pushes can not be found browser cache Some files pushed via node-spdy can not be found in browser cache Jun 28, 2016
@vigneshshanmugam
Copy link

@Tresdin Since you are running Service worker script on the page, resources will be fetched through that. Can you post the sw.js snippet which you have on the page.

@lewispham
Copy link
Author

@vigneshshanmugam Those requests won't be fetched through ServiceWorker simply because the client script is executed within the ServiceWorker.

@lewispham
Copy link
Author

Anyone interested in confirming this bug?

@sericaia
Copy link

sericaia commented Mar 6, 2017

@Tresdin I think I had the same problem. You're missing cache headers or your don't have a secure connection implemented.

See the 2nd hint (in the bottom) from this blogpost https://blog.yld.io/2017/03/01/optimize-with-http-2-server-push-and-service-workers/

I hope it helps!

@lewispham
Copy link
Author

lewispham commented Mar 7, 2017

@sericaia Thanks for the information. But I do fetch those files via HTTPS connections and they are also cached for 60 seconds (use Cache-Control header). From my above example, all of the file have the same caching header, but only 8 out of 14 files are cached properly. It's the primary reason making me believe it's a bug belonging to spdy.

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

No branches or pull requests

3 participants