5

I am using Uniserver for PHP web development and I am running windows 8.1 and have Kaspersky installed on system.

Most of my work involves working on WordPress websites.

Wordpress core files and some CSS and JavaScript files (e.g. CDN JavaScript or Google fonts) that require an Internet connection to work.

When the Internet is slow—or even down—my pages takes a lot of time to load, as they wait for Google fonts, CDN assets etc… to load; until it sometimes times out . This is frustrating, while developing as I need to refresh again and again.

However, if I turn off the Internet completely—by disconnecting WiFi—it loads instantly, as no Internet is present, and pages does not wait until a timeout occurs.

Usually while developing I would like to load the pages instantly, even if fonts don’t work, and CDN files fall back to local files.

But, I cannot turn-off the Interent, as I need Google all the time.

Is there anyway—via firewalls or some Apache config—to block the Internet for websites on localhost? So, my page loads faster while developing?

9
  • Maybe comment out CDN links while you develop? Firewall will block it but it will still timeout as operating system is aware that there is an active Internet connection. May 27 '15 at 8:11
  • 3
    Use 2 different browsers and took one offline mode? May 29 '15 at 20:25
  • @MustafaCan, I use chrome for dev and surfing both and would like to keep that way. I initially had this idea to use incorrect internet settings in one browser, but offline mode is much better. If all will fail, I'll use this.
    – Jashwant
    May 29 '15 at 20:36
  • 1
    As @MustafaCan wrote, you could use offline mode (in IE or Firefox). Alternatively, you could block access to the external resources by adding them to the HOSTS file or by using a caching DNS proxy like Acrylic and make use of its wildcards and regex matching features to block websites you don't want loading.
    – Vinayak
    May 29 '15 at 20:45
  • I also just found out about this. Since you use Chrome, it might be worth checking out.
    – Vinayak
    May 29 '15 at 20:57
8
+50

Here are the settings to consider in Chrome web browser:

  • create new Profile (new Person in People) specially for development (so your settings can be separated from the other profiles),
  • Disable Prefetch resources to load pages more quickly in Privacy settings and any other options which could potentially generate unneeded requests (such as prediction service, a web service to help resolve navigation errors, etc.),

or basically use Firefox instead and either Work Offline or decrease network.http.connection-timeout value in about:config.

Here are the suggestions for your WordPress website:

  • use aggregating and minimizing JS, CSS files if possible, so instead of dozens of requests, you've only one,
  • if you're using remote JS/CSS files, consider either disabling temporary plugins which are dealing with these (Google Analytics), re-upload them locally or consider using local alternatives (e.g. Google Analytics -> Open Web Analytics),
  • double check if actually you don't have any missing requests (such as missing image files) which works on your main environment - when you've missing images it could trigger CMS code it-self slowing down the page load,
  • install PHP caches (such as XCache) and memcached to speed up your development environment further more.

Consider using proxy:

  • use simple Proxy where you can short timeout (as probably it's not possible to configure timeout in Chrome),
  • use transparent proxy such as squid or varnishd (which would cache the remote files and provide local copy quick enough).

Other suggestions:

  • if you've specific remote hosts which are slowing down the page load, you can add them into /etc/hosts, for instance:

    127.0.0.1 google-analytics.com ssl.google-analytics.com
    

    This will treat them as they were local without having to change anything. So either provide local copy of them or it'll timeout faster.

  • configure your firewall to reject connections to specific hosts.

2

When the Internet is off, Chrome apparently uses the offline cache, which is why browsing is fast for these files (probably CSS etc.).

An idea : If the Apache website is on localhost, start Chrome with a non-existent proxy server for all websites except for localhost, with parameters such as :

 --proxy-server="127.0.0.1:1234" --proxy-bypass-list:localhost

This will effectively block Internet access, while leaving open Apache on localhost, which is the same effect as your turning off the WiFi. Chrome will then hopefully fall back to the cached page as found in the offline cache. You can therefore just create a shortcut to Chrome with these parameters when using the local Apache website.

For more info see :

1

If I understand your problem correctly, you have it all wrong. Fonts and scripts are not downloaded by apache. The web page is served once, and the locations of the fonts and scripts are specified in the response from the server. It is up to the browser to fetch the files specified in the response. Therefor blocking apache from accessing the internet is not a solution. You have to change your cashing policy of the page.

1

You cannot put your browser in work offline mode because your browser need an online access to the localhost url (which is served by your local apache server - but your browser does not know this).

The external core files will be loaded by your browser, not by your apache server. You can try to block access to specific urls of these external core files from being loaded by your browser. Blocking can be done in multiple ways, including by using proxy with custom rules like suggested by Vinayak in the comments.

I personally suggest using Adblock Plus with your Chrome (Chrome Web Store link). In Adblock Plus, specify rules to block those external core files so that your browser will not try to load them. Try using the domain option to only block urls loaded from your localhost page, e.g.

||google.com^$domain=localhost

Just disable Adblock when you want those files loaded.

1

There's a few options - run a real development environment on a VM - then you can run it nat only. Not as light as running it locally I guess

clever use of adblock - create specific sets of rules to block out resources you don't want loading. This may work outside the sites you're own but its something you can turn off and on at will. ublock is my current adblock of choice, and has this neat eyedropper option for elements

If you want something that will just affect the sites you work on, maybe use userside js scripts on whatever you host on localhost that will divert that elements - tampermonkey/greasemonkey might work. Not sure if anyone's ever done that before tho.

0

You mentioned firewalls -- I'd look into using iptables for this. You could easily script an online/offline mode, but if you block the traffic at the OS layer, then you don't have to worry about whether something is an artifact of the browser, the web server, or any other layer above it.

Just be sure you're familiar enough with iptables; it's not difficult to completely lock yourself out of a server if you end up DENYing or REJECTing ssh, for example.

2
  • He's running windows tho.
    – Journeyman Geek
    Jun 5 '15 at 12:36
  • Hah, so he is.. not sure how I missed that... nevermind iptables then, the command won't do much. :)
    – Tim S.
    Jun 5 '15 at 19:03
0

You can disable access to the internet by allowing only localhost files via .htaccess file..

Try: CREATE a new file named exactly .htaccess in the htdocs or the root directory of your project. COPY-PASTE the code below to this .htaccess file...

Order deny, allow
Deny from all
Allow from localhost

That's mostly all. If you cannot create the .htaccess file, then download it from here (winrar-format):

[ ::: link ::: ]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.