1

I opened my website in Chrome last night, then closed that tab, but didn't close browser. Today I failed to open my site in a new tab because jQuery(not use CDN) hits a syntax error: unexpected end of input.

My site always hits this error no matter how many times I refresh. But the error didn't happen again after hard refresh.

This problem happens many times in recent months.

I checked Chrome devtool, it says my jquery.min.js is loaded from memory cache. And it is not a whole file, only contains part of jquery library. That's why I got syntax error.

I did some research from google:

The lifetime of memory cache is attach to the lifetime of render process, which roughly corresponds to a tab.

So if I create a new tab to visit my site, stands to reason, jQuery should not be loaded from memory cache.

I expect browser do not load my files from memory again if I visit site in new tab.

Is there anything I can do to locate the problem source and fix it?

EDIT (2019-05-13):

Today hit this error again, but fortunately, I found new point seems helpful to this problem.

This is that request: Request info

See status code is 206 Partial Content (from memory cache).

And I have no idea why my request header contains 'Range' field.

Yan
  • 854
  • 1
  • 8
  • 15

1 Answers1

-1

You can't detect newtab in browser and load your jquery.min.js,But you can avoid loading from cache by adding timestamp into suffix of your lib like follows.

http://yoursite.com/lib/js/jquery.min.js?1557301884

You can achieve this in two ways

  • Case:1 If you are using server side page rendering means(PHP,JSP) just print the timestamp

  • Case:2 If Client side means some javascript stuff you have to do

Selvakumar
  • 21
  • 1
  • 6
  • Thanks for your help. But I have so many libs, I need cache them, or my users will wait too long. – Yan May 08 '19 at 08:09
  • Okay Yan, Did you analyzed the error **"unexpected end of input"** which lib file throwing exactly? – Selvakumar May 08 '19 at 13:49
  • Yes, sometimes jquery.min.js, sometimes jquery-ui.min.js or others. That's weird. I think the point is why broswer load libs from memory cache even if I opened a new tab to visit. – Yan May 09 '19 at 02:06