Title: Uncaught SyntaxError after activating first time
Last modified: September 28, 2019

---

# Uncaught SyntaxError after activating first time

 *  Resolved [lyden](https://wordpress.org/support/users/lydenyardley/)
 * (@lydenyardley)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/uncaught-syntaxerror-after-activating-first-time/)
 * Hello,
 * I love the idea of combining the best of both worlds with your plugin, but so
   far I’ve been unsuccessful in getting it to work.
 * I installed, activated and checked it, and there appeared to be no speed increase.
 * I opened up the console in Chrome DevTools and saw two errors:
 *     ```
       Uncaught SyntaxError: Identifier 'observer' has already been declared
           at flying-pages.min.js?ver=2.0.8:1
       ```
   
 * &
 *     ```
       Uncaught ReferenceError: flyingPages is not defined
           at (index):31
       ```
   
 * Any idea what’s going wrong here?
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Funcaught-syntaxerror-after-activating-first-time%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 15 replies - 1 through 15 (of 18 total)

1 [2](https://wordpress.org/support/topic/uncaught-syntaxerror-after-activating-first-time/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/uncaught-syntaxerror-after-activating-first-time/page/2/?output_format=md)

 *  Plugin Author [Gijo Varghese](https://wordpress.org/support/users/gijo/)
 * (@gijo)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/uncaught-syntaxerror-after-activating-first-time/#post-11977400)
 * [@lydenyardley](https://wordpress.org/support/users/lydenyardley/) Thanks for
   reporting the issue
 * After analyzing your site, I found a code that conflicts with Flying Pages. The
   code :
 *     ```
       <script>/* from https://usefulangle.com/post/108/javascript-detecting-element-gets-fixed-in-css-position-sticky */
       var observer = new IntersectionObserver(function(entries) {
       	// no intersection with screen
       	if(entries[0].intersectionRatio === 0)
       		document.querySelector("header").classList.add("scrolled");
       	// fully intersects with screen
       	else if(entries[0].intersectionRatio === 1)
       		document.querySelector("header").classList.remove("scrolled");
       }, { threshold: [0,1] });
   
       observer.observe(document.querySelector("#scroll-detector"));</script>
       ```
   
 * The error is because `observer` is already declared. You can fix it by renaming
   a variable. Here is the updated code if you want:
 *     ```
       <script>/* from https://usefulangle.com/post/108/javascript-detecting-element-gets-fixed-in-css-position-sticky */
       var scrollObserver = new IntersectionObserver(function(entries) {
       	// no intersection with screen
       	if(entries[0].intersectionRatio === 0)
       		document.querySelector("header").classList.add("scrolled");
       	// fully intersects with screen
       	else if(entries[0].intersectionRatio === 1)
       		document.querySelector("header").classList.remove("scrolled");
       }, { threshold: [0,1] });
   
       scrollObserver.observe(document.querySelector("#scroll-detector"));</script>
       ```
   
 * Pls try it and let me know
    -  This reply was modified 6 years, 8 months ago by [Gijo Varghese](https://wordpress.org/support/users/gijo/).
 *  Plugin Author [Gijo Varghese](https://wordpress.org/support/users/gijo/)
 * (@gijo)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/uncaught-syntaxerror-after-activating-first-time/#post-11977461)
 * I’ve also renamed the `observer` variable in Flying Pages to prevent conflicts
   with others. Just update to v2.0.9
 *  [Derrick Hammer](https://wordpress.org/support/users/pcfreak30/)
 * (@pcfreak30)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/uncaught-syntaxerror-after-activating-first-time/#post-11977562)
 * Hey Gijo, why aren’t you using an IFFE to remove any conflicts at all. Shouldn’t
   be using global space anyways?
 *  Plugin Author [Gijo Varghese](https://wordpress.org/support/users/gijo/)
 * (@gijo)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/uncaught-syntaxerror-after-activating-first-time/#post-11977569)
 * [@pcfreak30](https://wordpress.org/support/users/pcfreak30/) initially it was
   like that. But Swift Performance adds a try-catch (when you combine scripts) 
   around our lib and function which removes the scopes and causes errors. That’s
   why I had to go in this way
 *  [Derrick Hammer](https://wordpress.org/support/users/pcfreak30/)
 * (@pcfreak30)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/uncaught-syntaxerror-after-activating-first-time/#post-11977572)
 * IMHO, I think that should be something Swift Performance should be solving as
   the workaround by you I think will cause more problems in the long run.
 *  Plugin Author [Gijo Varghese](https://wordpress.org/support/users/gijo/)
 * (@gijo)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/uncaught-syntaxerror-after-activating-first-time/#post-11977584)
 * [@pcfreak30](https://wordpress.org/support/users/pcfreak30/) I’ll definitely 
   consider this. Will also contact Swift Performance guys if there is a proper 
   way to solve this
 *  [Derrick Hammer](https://wordpress.org/support/users/pcfreak30/)
 * (@pcfreak30)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/uncaught-syntaxerror-after-activating-first-time/#post-11977587)
 * Besides if they did that, how are things in webpack and es6 stuff handled?
 *  Plugin Author [Gijo Varghese](https://wordpress.org/support/users/gijo/)
 * (@gijo)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/uncaught-syntaxerror-after-activating-first-time/#post-11977592)
 * [@pcfreak30](https://wordpress.org/support/users/pcfreak30/) I didn’t get. Do
   you mean browser support?
 *  [Derrick Hammer](https://wordpress.org/support/users/pcfreak30/)
 * (@pcfreak30)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/uncaught-syntaxerror-after-activating-first-time/#post-11977596)
 * No, the fact webpack/es6 stuff is bundling a ton of anonymous functions and IFFE’s
   together, that the logic/heuristics Swift Performance use would wreak havoc.
 *  Plugin Author [Gijo Varghese](https://wordpress.org/support/users/gijo/)
 * (@gijo)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/uncaught-syntaxerror-after-activating-first-time/#post-11977606)
 * [@pcfreak30](https://wordpress.org/support/users/pcfreak30/) most of the plugins/
   scripts use a single js file or inline script. In the case of Flying Pages, we’ve
   both to get it to work. Something like this:
 *     ```
       <script src="/flying-pages.min.js"></script>
       <script>flyingPages({...options})</script>
       ```
   
 * If we add a try-catch or IIFE inside flying-pages.min.js, then it won’t be able
   to access beneath it
 *  [Derrick Hammer](https://wordpress.org/support/users/pcfreak30/)
 * (@pcfreak30)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/uncaught-syntaxerror-after-activating-first-time/#post-11977614)
 * You missed my point. I am saying the fact that a lot of applications/scripts 
   use ES6 code which is basically webpack. So if they are doing this to your code,
   they would likely nuke any bundled js module or application, custom or public.
   So overall they are doing something that’s a bad idea from what I know so far.
 *  Plugin Author [Gijo Varghese](https://wordpress.org/support/users/gijo/)
 * (@gijo)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/uncaught-syntaxerror-after-activating-first-time/#post-11977663)
 * [@pcfreak30](https://wordpress.org/support/users/pcfreak30/) Got it.
 * I just talked to Swift Performance guys. They’re removing try-catch! The update
   will be released probably tomorrow 🙂
 *  Thread Starter [lyden](https://wordpress.org/support/users/lydenyardley/)
 * (@lydenyardley)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/uncaught-syntaxerror-after-activating-first-time/#post-11981440)
 * Hi [@gijo](https://wordpress.org/support/users/gijo/)
 * Thanks so much for digging into this and providing various responses and effort
   to resolve. I implemented the observer tweak you provided, and updated your plugin
   successfully.
 * The console log errors have now gone away, but how can I verify that the plugin
   is preloading the pages behind links? In my eyeball testing, I can’t notice much
   difference… and can’t see anything happening in DevTools. But I may simply not
   be looking in the right places…?
 * What do you think?
 *  Plugin Author [Gijo Varghese](https://wordpress.org/support/users/gijo/)
 * (@gijo)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/uncaught-syntaxerror-after-activating-first-time/#post-11981484)
 * [@lydenyardley](https://wordpress.org/support/users/lydenyardley/) Can you share
   the url of your site so that I can check?
 *  Thread Starter [lyden](https://wordpress.org/support/users/lydenyardley/)
 * (@lydenyardley)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/uncaught-syntaxerror-after-activating-first-time/#post-11981528)
 * Sure – same is in my OP – [https://yardley.me](https://yardley.me)

Viewing 15 replies - 1 through 15 (of 18 total)

1 [2](https://wordpress.org/support/topic/uncaught-syntaxerror-after-activating-first-time/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/uncaught-syntaxerror-after-activating-first-time/page/2/?output_format=md)

The topic ‘Uncaught SyntaxError after activating first time’ is closed to new replies.

 * ![](https://ps.w.org/flying-pages/assets/icon.svg?rev=2145268)
 * [Flying Pages: Preload Pages for Faster Navigation & Improved User Experience](https://wordpress.org/plugins/flying-pages/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/flying-pages/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/flying-pages/)
 * [Active Topics](https://wordpress.org/support/plugin/flying-pages/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/flying-pages/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/flying-pages/reviews/)

 * 18 replies
 * 3 participants
 * Last reply from: [Gijo Varghese](https://wordpress.org/support/users/gijo/)
 * Last activity: [6 years, 8 months ago](https://wordpress.org/support/topic/uncaught-syntaxerror-after-activating-first-time/page/2/#post-11982951)
 * Status: resolved