question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Component is kept on cached page until next visit

See original GitHub issue

Hi, and thanks for the plugin!

I’ve found that there can be 2 similar components on page when returning back to page which was previously cached:

  • Open page with component
  • Go to another one
  • Return to first one (via visit, not back button).

When component is created with inline js in page, it runs twice on second visit: when page is shown from cache and then for fresh one. This is not a problem in most cases, but my component was polling some api (it’s stopped in beforeDestroy), so I noticed that all requests are doubled.

I’ve slightly changed original plugin to handle such cases. It’s made with coffeescript and uses jquery - i’m not familiar with modern js. However, i hope this may help:

components = []

# Destroy components on current page when moving to another.
$(document).on 'turbolinks:visit', ->
  component.$destroy() for component in components

# Clear components on curent page which are not present anymore.
$(document).on 'turbolinks:load', ->
  for component in components
    component.$destroy() unless $.contains(document, component.$el)

Vue.TurbolinksAdapter =
  beforeMount: ->
    # If this is the root component,
    # we want to cache the original element contents to replace later.
    # We don't care about sub-components, just the root
    if @ == @$root
      components.push(@)
      @$originalEl = @$el.outerHTML

  destroyed: ->
    # We only need to revert the html for the root component.
    @$el.outerHTML = @$originalEl if @ == @$root

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
printercucommented, Nov 28, 2017

Hi! Any update on it? Did sample app help? I’ve found an issue in my original mixin that it didn’t clean up old instances. Here is updated one, which can be used either as plugin or as mixin: https://gist.github.com/printercu/e202851c370ffc38bcdedeb8300d417e

0reactions
jeffreyguenthercommented, Nov 29, 2017

Are you encountering any other issues if you follow the pattern set out by @excid3?

If you’d prefer a more structured approach to page specific JS, check out https://github.com/kieraneglin/punchbox. It hides away some of the complexity of needing to test for the presence of an element. Both approaches work great and allow multiple Vue components on a page.

If there’s no bug present, I’m going to close this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chrome keeps loading a old cache of my website
I tried to clean the browser cache, use igcognito mode, and clean DNS cache. The old cached page is still being loaded. This...
Read more >
Caching Behavior of Web Browsers - F5 Networks
When a user visits a web page, the contents of that page can be stored in the browser's cache so it doesn't need...
Read more >
What is Website Cache & How Do You Clear Your Browser's ...
Click on “Privacy, search, and services.” Scroll down to “Clear browsing data” and click on the “Choose what to clear” button. Change the...
Read more >
Cache Busting a React App - DEV Community ‍ ‍
We want to figure out a way to clear the browser or service worker cache every time a new version of our app...
Read more >
HTTP caching - MDN Web Docs
The HTTP cache stores a response associated with a request and reuses the stored response for subsequent requests.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found