jekyll-offline icon indicating copy to clipboard operation
jekyll-offline copied to clipboard

Duplicate entries

Open DirtyF opened this issue 9 years ago • 2 comments

Hi,

First of all, thanks for this plugin @jeremiak

I tested it locally and here is what's inside the generated sw.js file:

var urlsToCache = [];

  urlsToCache.push("");

  urlsToCache.push("");

  urlsToCache.push("");

  urlsToCache.push("");

  urlsToCache.push("");

  urlsToCache.push("");

  urlsToCache.push("");

  urlsToCache.push("");

  urlsToCache.push("");

  urlsToCache.push("");

  urlsToCache.push("");




    urlsToCache.push("/404.html");



    urlsToCache.push("/404.html");



    urlsToCache.push("/a-propos/");



    urlsToCache.push("/a-propos/");





    urlsToCache.push("/humans.txt");



    urlsToCache.push("/");



    urlsToCache.push("/");





    urlsToCache.push("/assets/css/main.css");





    urlsToCache.push("/presentations/ne-passons-pas-a-cote-des-choses-simples/");





    urlsToCache.push("/robots.txt");



    urlsToCache.push("/2016/01/28/comprendre-le-mvp/");



    urlsToCache.push("/2016/01/28/comprendre-le-mvp/");



    urlsToCache.push("/2016/05/21/la-stack-jam/");



    urlsToCache.push("/2016/05/21/la-stack-jam/");



    urlsToCache.push("/2016/08/30/ten-ways-to-make-a-product-great/");



    urlsToCache.push("/2016/08/30/ten-ways-to-make-a-product-great/");



var CACHE_NAME = 'frank-taillandier-cache-v1';

self.addEventListener('install', function(event) {
  // Perform install steps
  event.waitUntil(caches.open(CACHE_NAME).then(function(cache) {
    return cache.addAll(urlsToCache);
  }).catch(function(err) {
    console.log('cache add err', err);
  }));
});

self.addEventListener('fetch', function(event) {
  event.respondWith(
    caches.open(CACHE_NAME).then(function(cache) {
      return cache.match(event.request).then(function (response) {
        return response || fetch(event.request).then(function(response) {
          cache.put(event.request, response.clone());
          return response;
        });
      });
    })
  );
});

// strategies from the offline cookbook by jake archibald
// https://jakearchibald.com/2014/offline-cookbook/#serving-suggestions-responding-to-requests



  self.addEventListener('fetch', function(event) {
    event.respondWith(
      caches.open(CACHE_NAME).then(function(cache) {
        return fetch(event.request).then(function(response) {
          cache.put(event.request, response.clone());
          return response;
        });
      })
    );
  });


At the beginning there are empty URLs then some duplicates, unlike the sitemap, all URLs are not present. I don't know how is this supposed to work, but I thought I'll give you a feedback.

I'm using latest Jekyll version 3.3 and the repo is here: https://github.com/DirtyF/frank.taillandier.me

Thanks for any help you could provide on grabbing how this works.

DirtyF avatar Oct 21 '16 09:10 DirtyF

same issue here. lots of duplicates and assets not found at all.

jbspeakr avatar Feb 11 '17 14:02 jbspeakr

Try modifying the top of the sw.js file from this:


{% for post in site.posts %}
  urlsToCache.push("{{ post.permalink }}");
{% endfor %}

{% for page in site.pages %}
  {% if page.permalink %}
    urlsToCache.push("{{ page.permalink }}");
  {% endif %}

  {% if page.url %}
    urlsToCache.push("{{ page.url }}");
  {% endif %}
{% endfor %}

var CACHE_NAME = '{{ site.title | slugify }}-cache-v1';

To this:

var urlsToCache = [];

/*posts*/
{% for post in site.posts %}
  urlsToCache.push("{{ post.url }}");
{% endfor %}
/*pages*/
{% for page in site.pages %}
  {% if page.permalink %}
    urlsToCache.push("{{ page.permalink }}");
  {% endif %}

  {% if page.url %}
    urlsToCache.push("{{ page.url }}");
  {% endif %}
{% endfor %}

/*static files*/
{% for file in site.static_files %}
    urlsToCache.push("{{file.path}}");
{% endfor %}
/*html pages*/
{% for page in site.html_pages %}
    urlsToCache.push("{{ page.url }}");
{% endfor %}

var CACHE_NAME = '{{ site.title | slugify }}-cache-v1';

Booligoosh avatar Aug 05 '17 02:08 Booligoosh