Laravel IndexNow is a package that provides a wrapper to use the IndexNow API in Laravel. This makes indexing new web pages in (some) search engines easy and fast. It makes for a nice little addition to sitemaps. IndexNow is an API created by Microsoft Bing & Yandex to allow you to submit page changes to their search engines quickly. Submission to one search engine will automatically pass the submission on to the others.
You can install the package via composer:
composer require laravel-freelancer-nl/laravel-index-now
You can publish the config file with:
php artisan vendor:publish --tag="index-now-config"
The IndexNow API matches the request key to a key file within the host domain. To generate the keyfile you use the following artisan command:
php artisan index-now:generate-key
This will create a keyfile in the
public_dir() of your project and output the key. Copy the displayed key and place it in your .env file.
If you've set a key location in the config it will be prefixed to the file. Running this command multiple times will generate a new key and key file.
You can submit one or more pages per request by calling the facade and passing the url(s) to the submit method.
Note that the urls must be fully qualified without query parameters and without a fragment.
Submit a single page
use LaravelFreelancerNL\LaravelIndexNow\Facades\IndexNow; IndexNow::submit('https://dejacht.nl/jagen');
Submit multiple pages
To submit multiple pages at once just add an array of URLs.
use LaravelFreelancerNL\LaravelIndexNow\Facades\IndexNow; IndexNow::submit([ 'https://dejacht.nl', 'https://dejacht.nl/fotoquiz/', 'https://dejacht.nl/jagen/', 'https://dejacht.nl/jachtvideos/', ]);
You can delay page submissions by using the delay submission method. This dispatches the IndexNowSubmitJob with a delay in seconds as configured. The job is unique by payload, so multiple submissions of the same URLs won't push a job to the queue before the current one is handled.
use LaravelFreelancerNL\LaravelIndexNow\Facades\IndexNow; IndexNow::delaySubmission('https://devechtschool.nl');
You can override the configured default delay by adding your own.
use LaravelFreelancerNL\LaravelIndexNow\Facades\IndexNow; IndexNow::delaySubmission('https://devechtschool.nl', 100);
When to delay submits
It isn't uncommon for people to make additional edits after creating or updating a page. On these actions, it is a good idea to delay the submission.
When deleting pages you can just submit the URLs immediately.
For more details, Visit Github.
Published at : 27-06-2022
I am a highly results-driven professional with 12+ years of collective experience in the grounds of web application development especially in laravel, native android application development in java, and desktop application development in the dot net framework. Now managing a team of expert developers at Codebrisk.