title: How to close previous EventSource
body: <pre class="lang-html prettyprint-override"><code>&lt;button onclick="hoge()"&gt;hoge&lt;/button&gt;
  &lt;script&gt;
  function hoge(){
    if(es){
      es.close()
    }
    var es = new EventSource('/hoge')
    es.onmessage = function(e) {
      console.log(e)
    }
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>I want to save resources, so it clicked and start connect EventSource.<br>
  The new connection start each time clicked, so I want to disconnect the previous connection.<br>
  I tried the above code but it didn't work. How should I do please.</p>