Skip to main content

Snippets

Working With AJAX Loading (Ajax Loading Overlay)

An AJAX loading overlay is a UI element that covers the page (or a section of it) while an asynchronous request is in progress. It prevents users from clicking a button multiple times and gives clear visual feedback that something is happening in the background.

Getting Recent Posts Outside Of WordPress

Many sites do use WordPress for blogging but they do not use it as back-end for whole site. (Your site or app may be one of them.) There may be a scenario in which you have to display recent posts from WordPress blog, on a page which is outside of WordPress. No problem. You might know that WordPress is quite flexible, hence you can handle such scenario with a small code. There are two ways to achieve this. You can either take advantage of WordPress loop itself or if you don't want to deal with WordPress loop then you can use other way also. If you don't want WordPress loop So you don't want to take advantage of WordPress loop? Then you can use wp_get_recent_posts(). According to WordPress codex: wp_get_recent_posts() will return a list of posts. Different from get_posts which returns an array of post objects. How to use it? Just copy paste following code in page where you want to list the Recent Posts include( 'wp-load.php' ); // Get the last 10 posts $recent_posts = wp_get_recent_posts( array( 'numberposts' => 10, 'post_type' => 'post', 'post_status' => 'publish', ) ); // Display them as list echo '<ul>'; foreach ( $recent_posts as $post ) { echo '<li><a href="', get_permalink( $post['ID'] ), '">', $post['post_title'], '</a></li>'; } echo '</ul>'; You can simply change numberposts parameters value to change the number of posts you want to retrieve.

HTML5 Prefetching Api

Note: This post was written in 2012. Link prefetching is still valid, but modern browsers now support more targeted hints like rel="preload", rel="preconnect", and rel="prefetch" — each serving a different purpose. The MDN docs are still the best reference. Making websites faster is something both developers and browsers are constantly working on. There are plenty of well-known techniques for this — CDNs, minified JavaScript and CSS, image sprites, smart caching headers in .htaccess, and so on. But one lesser-known technique that most developers overlook entirely is link prefetching. What is link prefetching? According to MDN: Link prefetching is a browser mechanism which utilizes browser idle time to download or prefetch documents that the user might visit in the near future. A web page provides a set of prefetching hints to the browser, and after the browser is finished loading the page, it begins silently prefetching specified documents and stores them in its cache. When the user visits one of the prefetched documents, it can be served up quickly out of the browser's cache. In simple terms: you hint to the browser which page the user is likely to visit next, and the browser quietly downloads it in the background during idle time. When the user clicks through, the next page loads nearly instantly because it's already cached. How to implement it It's just a <link> tag with rel="prefetch" or rel="next": <!-- Prefetch a full page --> <link rel="prefetch" href="https://ankurm.com/lab/blog/api/using-localhost-for-facebook-app-development/1091/" /> <!-- Prefetch an image --> <link rel="prefetch" href="https://ankurm.com/wp-content/uploads/2012/03/logo.png" />

Redirecting www To non-www And Vice Versa

Note: This post was written in 2012. The .htaccess rules below still work on Apache servers, but modern setups (NGINX, Caddy, Apache 2.4 with virtual hosts) handle redirects differently. The rules also use http:// — update them to https:// for any SSL-enabled site. Every domain can be accessed through two different URLs. Take example.com — it's reachable as both example.com and www.example.com. The same applies to subdomains. From a user's point of view this doesn't matter much, but from an SEO standpoint it's a problem. Having the same content available on two different URLs can be flagged as duplicate content and hurt your search rankings.

AddHandler vs AddType : Apache Directive

AddHandler and AddTypes are two directives which define how file should be treated by apache. AddType defines how a client (example A web browser) should deal with the file or data stream, while AddHandler defines how a server should parse a file. Read this post for more information on them.

Programmatically Set Proxy Settings In Visual Basic

Proxies are very useful while developing application especially in those who need internet connection. Proxies are used according to applications requirement and organization needs. This post will explain you a code which can be used for creating a application only proxy connection. Go ahead! Integrate it in your project.

HTML 5 DnD Download: A Quick Implementation

So whatever you are, a developer or a user you might know about Drag and Drop Upload. You might have used it on Facebook for uploading photos or in G-Mail for uploading attachments and even on other sites also. Here on the web, there are many implementations and tutorial are available for creating Drag and Drop upload but there are only few for Drag and Drop Download. Here in this post you will get a quick look on this HTML 5 feature.

Speed Up Your Site with Chrome Prerendering

While stumbling upon the web for Web 3.0, I come across a best tool for web designers.  You might know that there is an option for turning on or turning off Network Prediction in Google Chrome. Google claims that this option is useful to decrease load time of a page & the page is instantly loaded on your browser when you click on link. This feature is also referred as Instant Pages. As a developer, here is a small article for you which will help you to enable this feature on your website.

Behind The Scenes: The HJKL Keys

If you are a Gmail user, with keyboard short codes enabled then you might have noticed that you can use j and k keys for navigation within GMail. You can use J key to navigate to previous (older) message & K key to navigate to the newer message from your inbox. Even the navigation using J and K keys is quite popular in others website also such as makeuseof.com , Google Reader and even at tumblr also. This J-K key combination may be found at many blog sites also. Even many developers use this keys in their applications for navigation purposes. Now the question is why J & K only. Why not others ? Let's discover the interesting answer of it.