How to Fix Leverage browser caching connect.facebook.net/en_US/fbevents.js?

74

Unfortunately you can't directly remove the Insights warning. The PageSpeed tool can't tell that you don't own the facebook.net domain and therefore have no control over the response headers.

Presumably Facebook have given this file a short(ish) cache expiry time so they can deploy changes to it and have them take effect pretty quickly.

I say you can't "directly" remove the warning because there is a fudgey workaround that's been posted on Stack Overflow. It's not a very nice workaround though and a lot of people (myself included) would say it's massive overkill and creates more problems than it solves.

1 - Fudge it

You could create a job somewhere that copies the Facebook script to your server or a suitable CDN on a regular basis - maybe every 20 minutes as that's the current header expiry that Facebook is using. When you serve it you could increase the cache expiry time in the header to whatever you want. This would remove the warning from the PageSpeed report.

However, I think this is a really bad idea for a couple of reasons...

  • If Facebook release a breaking change to the script you'll have old versions of it sitting in browser caches for a long time - longer than Facebook intended.
  • You'd be introducing a number of things that could go wrong. Your job could fail, it could create a blank file, or no file at all! It might not run for several days and miss vital updates to the script.

I call this option a fudge because it is. It's not actually fixing a problem, because in this instance there isn't really a problem to fix.

2 - Remove it

Do you need to load the Facebook script? Can it just be removed?

If you need to load it to deliver a particular UX you should just expect it to affect your performance score and move on.

3 - Ignore it (Recommended)

PageSpeed is a useful tool and can raise some important performance issues when it comes to maximizing the efficiency of your website, but you should use PageSpeed and other similar tools only as a guide.

Sometimes resolving all of the "problems" these tools raise will just make more problems elsewhere. Fix the important stuff that you have control over.

More reading:

Share:
74
user1188849
Author by

user1188849

Updated on September 18, 2022

Comments

  • user1188849
    user1188849 almost 2 years

    My Map app has a " Select city " button to show worldCitiesList when clicked using the following code:

    [self.navigationController presentModalViewController:self.worldCitiesListNavigationController animated:YES];
    

    But now the place for the " Select city " button has to be replaced by another button.

    the " Select city " button has to be relocated to another viewcontroller created from the MapViewController by the following code:

    [self.navigationController presentModalViewController:self.tableViewNavigationController animated:YES];
    

    The worldCitiesList can be showed from the tableViewNavigationController. But we want it is still showed from the MapViewController as before.

    So in the button of backing to the MapViewController from the tableViewNavigationController, I use following code to first back to MapViewController, then to show the worldCityList:

    - (void) backMapView:(id)sender
    {
        [self.navigationController dismissModalViewControllerAnimated:YES];
    
        [self.navigationController presentModalViewController:self.worldCitiesListNavigationController animated:YES];
    }
    

    But my app just return to MapViewControler, but not show the worldCityList further.

    In my WorldCitiesListController.m, my iOS app just goes to @synthesize, but not go to viewWillAppear and viewDidLoad further.

    Please help. thanks in advance !!!

    • WrightsCS
      WrightsCS almost 12 years
      Post the stack trace (if any).
    • Jesse Rusak
      Jesse Rusak almost 12 years
      Try removing your dismissModalViewControllerAnimated call and see what happens
    • coneybeare
      coneybeare almost 12 years
      I think you are confusing compiled obj-c with a scripted language. The file is not read top to bottom, but compiled. Saying the app just "goes to @synthesize" makes no sense.
    • Matt Hudson
      Matt Hudson almost 12 years
      I think he may be talking about in the debugger when you step through it stops at @synthesize.
    • user1188849
      user1188849 almost 12 years
      thanks you all for your prompt replies! the BackMapView button does nothing if I remove : [self.navigationController dismissModalViewControllerAnimated:YES]; In other words, app still stays with TableViewController interface.
    • user1188849
      user1188849 almost 12 years
      yea, inturbidus. I set breakpoints in 'WorldCitiesListController.m', it doesnot go to 'viewdidLoad' and 'viewWillappear'. I just goes to ' @synthesize cityList, delegate' . I even set NSLog within 'viewdidLoad' and ' viewWillAppear' to double-check. it really doesnot step into the above 2 places. thanks
    • user1188849
      user1188849 almost 12 years
      Dear WrightsCS, the NSLog doesnot show any useful info.I 'll appreciate if any good method to recommend how to get the stack trace.thanks!
    • nicktones
      nicktones almost 12 years
      I think we need to see more code. Have you set up a delegate?
    • user1188849
      user1188849 almost 12 years
      My question solved by: dismissModalViewControllerAnimated: NO.