Friday, May 31, 2024

Tips for Improving Website Speed

Speed of the website is very much important while developing a website. In my last blog I explained how to find the speed of your website. Now in this blog we will discuss how to improve the speed of the website. Below are some tips to improve the speed of the website 

Optimize Images: Compress images without losing quality.

Enable Caching: Use browser and server caching to reduce load times.

Minify CSS and JavaScript: Remove unnecessary characters from code to reduce file sizes.

Use a Content Delivery Network (CDN): Distribute content across multiple servers to speed up delivery.

Reduce HTTP Requests: Limit the number of requests your site makes to load a page.

Optimize Server Response Time: Ensure your server responds quickly to requests.

Using these tools and implementing their recommendations can significantly improve your website’s performance.

Improving the speed of your website involves several strategies, from optimizing your code to leveraging various performance-enhancing technologies. Here’s a comprehensive guide to help you increase your website’s speed:

1. Optimize Images

  • Compress Images: Use tools like TinyPNG, ImageOptim, or online services like Kraken.io to reduce image file sizes without compromising quality.
  • Use Correct Formats: Use JPEG for photographs, PNG for images with transparency, and SVG for icons and vector graphics.
  • Lazy Loading: Implement lazy loading to delay the loading of images until they are about to enter the viewport.

2. Enable Caching

  • Browser Caching: Configure your web server to set caching headers for static resources, so browsers can cache them locally.
  • Server-Side Caching: Use caching mechanisms like Memcached or Redis to store frequently accessed data in memory.

3. Minify CSS, JavaScript, and HTML

  • Minify Files: Remove unnecessary characters, whitespace, and comments from your code. Tools like UglifyJS, CSSNano, and HTMLMinifier can help with this.
  • Concatenate Files: Combine multiple CSS and JavaScript files into single files to reduce the number of HTTP requests.

4. Use a Content Delivery Network (CDN)

  • CDN Services: Services like Cloudflare, Akamai, and Amazon CloudFront distribute your content across multiple servers globally, reducing the distance data needs to travel to reach the user.

5. Optimize Server Response Time

  • Choose a Fast Web Host: Select a reliable hosting provider known for high performance.
  • Upgrade Server Resources: Increase server resources such as CPU and RAM if you’re on a VPS or dedicated server.
  • Use Fast Software: Implement server-side technologies like NGINX or LiteSpeed instead of Apache for faster response times.

6. Reduce HTTP Requests

  • Limit External Resources: Reduce the number of external scripts, fonts, and stylesheets.
  • Inline Small CSS and JavaScript: For very small CSS and JavaScript files, inline them directly into the HTML to reduce the number of requests.

7. Enable Gzip Compression

  • Compress Files: Enable Gzip compression on your server to reduce the size of HTML, CSS, and JavaScript files sent to the browser.

8. Leverage Browser Caching

  • Set Expiry Dates: Use HTTP headers to set expiry dates or max-age for static resources, so browsers cache them and don’t reload on every visit.

9. Optimize Database Queries

  • Database Indexing: Ensure that your database is properly indexed to speed up queries.
  • Use Efficient Queries: Optimize your SQL queries to reduce load times, and avoid retrieving unnecessary data.

10. Reduce Plugins and Third-Party Scripts

  • Limit Plugins: Deactivate and delete any unnecessary plugins, especially those that load a lot of scripts and styles.
  • Asynchronous Loading: Load third-party scripts asynchronously to prevent them from blocking the rendering of the page.

11. Implement AMP (Accelerated Mobile Pages)

  • Use AMP: For content-heavy pages, implement AMP to create fast-loading versions of your pages for mobile users.

12. Use Modern Web Technologies

  • HTTP/2: Upgrade to HTTP/2 for improved performance, as it allows multiplexing multiple requests over a single connection.
  • Prefetching and Preloading: Use link prefetching and preloading to load resources in advance.

13. Monitor Performance Regularly

  • Regular Testing: Use tools like Google PageSpeed Insights, GTmetrix, Pingdom, and WebPageTest to regularly check your website’s performance.
  • Continuous Optimization: Keep your site optimized by regularly reviewing and updating your performance strategies based on test results.

Conclusion

Implementing these strategies can significantly improve your website's loading speed, resulting in a better user experience and potentially higher search engine rankings. Regular monitoring and continuous optimization are key to maintaining high performance as your site evolves.

How to check the speed of your website

Checking the speed of your website is essential for ensuring a good user experience and optimizing your site for search engines. Here are several tools and methods to help you check and analyze your website’s speed:

1. Google PageSpeed Insights:

Google PageSpeed Insights is a free tool that analyzes the content of a web page and provides suggestions to make that page faster. It provides both mobile and desktop results.

How to Use:

  1. Go to [Google PageSpeed Insights] (https://developers.google.com/speed/pagespeed/insights/).
  2. Enter your website URL and click "Analyze".
  3. Review the performance score and suggestions for improvement.

2. GTmetrix:

GTmetrix provides detailed reports on your website's performance, including page load time, total page size, and the number of requests.

 

How to Use:

  1. Go to [GTmetrix](https://gtmetrix.com/).

  2. Enter your website URL and click "Test your site".

  3. Review the detailed performance report, including PageSpeed and YSlow scores.

 

3. Pingdom Website Speed Test:

Pingdom's tool allows you to test the speed of your website from different locations around the world and provides a performance grade and suggestions for improvement.

 

How to Use:

  1. Go to [Pingdom Website Speed Test](https://tools.pingdom.com/).

  2. Enter your website URL, select a test location, and click "Start Test".

  3. Analyze the performance summary and recommendations

4. WebPageTest:

WebPageTest offers advanced testing options, including multi-step transactions, video capture, content blocking, and more. It provides a detailed performance review.

 

How to Use:

  1. Go to [WebPageTest](https://www.webpagetest.org/).

  2. Enter your website URL and select test settings (e.g., location, browser).

  3. Click "Start Test" and review the comprehensive performance analysis.


5. Lighthouse: 

Lighthouse is an open-source, automated tool for improving the quality of web pages. It has audits for performance, accessibility, progressive web apps, SEO, and more.

 

How to Use:

  1. Open Chrome browser.

  2. Go to your website and open DevTools (Ctrl+Shift+I or Cmd+Option+I).

  3. Go to the "Lighthouse" tab.

  4. Click "Generate report".

 

6. Chrome DevTools: 

Chrome DevTools provides in-depth performance analysis directly within the Chrome browser.

 How to Use:

  1. Open Chrome browser.

  2. Visit your website.

  3. Open DevTools (Ctrl+Shift+I or Cmd+Option+I).

  4. Go to the "Network" tab and reload the page to see the loading times and network requests.

  5. Go to the "Performance" tab and record a page load to get a detailed breakdown of the performance metrics.

 

7. Cloudflare: 

If you use Cloudflare, it provides its own analytics and performance metrics that can help you understand and improve your site speed.

 How to Use:

  1. Log in to your Cloudflare account.

  2. Select your site.

  3. Navigate to the "Speed" tab to see performance metrics and suggestions. 


Thursday, April 11, 2024

How to make php artisan to run on different port

When we want to run two servers on the same machine we may need to have two different ports.  We can change the default port for the Artisan development server by two ways.
        1. Changing the port number in env file.
        2. Through port argument to php artisan command.

1. .Env file change: 
        you can add the parameter SERVER_PORT to the .env file in the root directory of your project. Then, you can use the command php artisan serve to start the server with the new port. The default port is 8000, but serve will scan up to port 8009 for available ports

2. Passing argument to the command
        We can pass the --port argiment to php artisan serve command and run it to start the localhost server on the specified port
        php artisan serve --port:8080

       
Artisan Serve Improvements

In previous releases of Laravel, Artisan's serve command would serve your application on port  8000. If another serve command process was already listening on this port, an attempt to serve a second application via serve would fail. Beginning in Laravel 5.8, serve will now scan for available ports up to port 8009, allowing you to serve multiple applications at once.

Monday, April 8, 2024

Various collaboration options with a company on research product development

Collaborating with a company on research and product development without significant financial impact on your organization can be achieved through various arrangements. Here are some options:

1. Joint Research Agreements (JRAs):
- JRAs allow companies to share resources, expertise, and risks in research projects.
- Both parties contribute resources such as personnel, equipment, and facilities.
- Costs and benefits are shared based on agreed-upon terms.

2. Grant Funding: - Seek grants from government agencies, non-profit organizations, or industry consortia to fund collaborative research. - Grants can cover project costs, including personnel salaries, equipment, and materials. - Many grants specifically support collaborative projects between academia and industry. 3. Sponsored Research: - Companies can sponsor research conducted by your organization. - The sponsor provides financial support for the research project without direct involvement in its execution. - Intellectual property rights are typically negotiated in sponsored research agreements. 4. In-kind Contributions: - Companies can contribute resources other than money, such as equipment, materials, or access to proprietary data or technology. - These contributions can significantly reduce the financial burden on your organization. 5. Technology Licensing: - If your organization has developed intellectual property relevant to the company's interests, consider licensing it to them. - The company can then take the lead in further development and commercialization, while your organization receives licensing fees or royalties. 6. Collaborative Grants: - Identify grant opportunities that specifically encourage collaboration between academia and industry. - Collaborate with the company to jointly apply for such grants, leveraging each other's expertise and resources. 7. Joint Development Agreements (JDAs): - JDAs outline the terms of collaboration between two parties to jointly develop a product or technology. - Costs and risks are shared, with each party contributing resources and expertise. 8. Crowdfunding: - Consider crowdfunding platforms to raise funds for specific research projects. - This approach allows you to engage the public and potentially attract funding without relying solely on your organization's finances. 9. Revenue Sharing Agreements: - If the collaborative project leads to commercialization and revenue generation, negotiate revenue-sharing agreements with the collaborating company.
When considering any collaboration, ensure that the terms are clearly defined in legally binding agreements to protect the interests of all parties involved. Consult with legal and financial advisors to navigate the complexities of collaborative arrangements effectively.


cvc-complex-type.2.4.a: Invalid content was found starting with element 'base-extension'. One of '{layoutlib}' is expected Error in Android


We were facing this issue many times when we download project from github. We are using new Android studio. 

Error was: cvc-complex-type.2.4.a: Invalid content was found starting with element 'base-extension'. One of '{layoutlib}' is expected. 

This is not the gradle issue. When we search this over internet, we get lot of answers as it's a gradle issue. But following all those solutions are in vain as this is not actually a gradle issue.

We solved this issue with some experiments. 

Android SDK configuration file ~/Library/Android/sdk/platforms/android-32/package.xml has an extra tag named base-extension compared to the same file of other API levels. Removing this tag solves the problem.
Delete downloaded Android API 32 SDK Platform from SDK Manager (Tools → SDK Manager) also solves the problem (you can redownload after deletion). Maybe the Android studio team noticed the problem, redownloading API 32 platform files, the base-extension tag disappeared from the API 32 package.xml