---
title: Browsersync Proxy URL from DOTENV file
date: 2020-08-21T09:06:00-04:00
author: cc_admin
canonical_url: "https://caffeinecreations.ca/blog/browsersync-proxy-url-from-dotenv-file/"
section: Blog
---
![Browsersync proxy](https://caffeinecreations.ca/uploads/blog/_1920x660_crop_center-center_none_ns/browsersync-proxy1.png)

- [Web Development](https://caffeinecreations.ca/blog/category/web-development/), [Code](https://caffeinecreations.ca/blog/category/code/), [Tutorial](https://caffeinecreations.ca/blog/category/code/tutorial/)

# Browsersync Proxy URL from DOTENV file

I'm working on a couple of projects where other developers will be contributing as well. The issue with this is my build process uses Laravel Mix to compile tailwind, minimize &amp; concatenate javascript, create critical css, and various other tasks including the most important one Browsersync to reload the browser each time I make changes to the code.

Until now this has worked great as I just added in my local domain to the proxy setting in Browsersync and it worked. However the other contributors are likely to use different local urls when setting up their sites and that won't work as the `webpack.mix.js` file is in version control and needs to be the same for each developer except for the proxy url setting.

It took some digging, googling, as well as trial and error but I got it working despite not being able to find any documentation.

In your DOTENV file add this variable and replace `https://my-site.ddev.site` with the local url of your project

```
<button class="absolute z-10 flex items-center justify-center w-10 h-10 -translate-y-1/2 bg-gray-300 border rounded-full shadow-sm border-grey-darker -right-4 -top-4" clipboard="" title="Copy to Clipboard" to="" type="button" x-clipboard.raw="BROWSERSYNC_PROXY_URL="https://my-site.ddev.site"" x-data=""><svg class="h-5 w-5" viewbox="0 0 64 64" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
  <path d="M53.98 9.143h-3.97c-.082 0-.155.028-.232.047V5.023C49.778 2.253 47.473 0 44.64 0H10.217C7.384 0 5.08 2.253 5.08 5.023v46.843c0 2.77 2.305 5.023 5.138 5.023h6.037v2.268c0 2.67 2.216 4.843 4.941 4.843H53.98c2.725 0 4.942-2.173 4.942-4.843v-45.17c0-2.671-2.217-4.844-4.942-4.844zM7.11 51.866V5.023c0-1.649 1.394-2.991 3.106-2.991H44.64c1.712 0 3.106 1.342 3.106 2.99v46.844c0 1.649-1.394 2.991-3.106 2.991H10.217c-1.712 0-3.106-1.342-3.106-2.99zm49.778 7.29c0 1.551-1.306 2.812-2.91 2.812H21.195c-1.604 0-2.91-1.26-2.91-2.811v-2.268H44.64c2.833 0 5.138-2.253 5.138-5.023V11.128c.077.018.15.047.233.047h3.968c1.604 0 2.91 1.26 2.91 2.811v45.17z"></path>
  <path d="M38.603 13.206H16.254a1.015 1.015 0 1 0 0 2.032h22.35a1.015 1.015 0 1 0 0-2.032zM38.603 21.333H16.254a1.015 1.015 0 1 0 0 2.032h22.35a1.015 1.015 0 1 0 0-2.032zM38.603 29.46H16.254a1.015 1.015 0 1 0 0 2.032h22.35a1.015 1.015 0 1 0 0-2.032zM28.444 37.587h-12.19a1.015 1.015 0 1 0 0 2.032h12.19a1.015 1.015 0 1 0 0-2.032z"></path>
</svg>
<div class="sr-only">Copy to clipboard</div></button>```html
BROWSERSYNC_PROXY_URL="https://my-site.ddev.site"
```
```

Near the top of your `webpack.mix.js` file add this code - the last line is the important part.

```
<button class="absolute z-10 flex items-center justify-center w-10 h-10 -translate-y-1/2 bg-gray-300 border rounded-full shadow-sm border-grey-darker -right-4 -top-4" clipboard="" title="Copy to Clipboard" to="" type="button" x-clipboard.raw="const mix = require("laravel-mix");

// Pull the proxy url from dotenv file
let proxy_url = process.env.BROWSERSYNC_PROXY_URL;" x-data=""><svg class="h-5 w-5" viewbox="0 0 64 64" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
  <path d="M53.98 9.143h-3.97c-.082 0-.155.028-.232.047V5.023C49.778 2.253 47.473 0 44.64 0H10.217C7.384 0 5.08 2.253 5.08 5.023v46.843c0 2.77 2.305 5.023 5.138 5.023h6.037v2.268c0 2.67 2.216 4.843 4.941 4.843H53.98c2.725 0 4.942-2.173 4.942-4.843v-45.17c0-2.671-2.217-4.844-4.942-4.844zM7.11 51.866V5.023c0-1.649 1.394-2.991 3.106-2.991H44.64c1.712 0 3.106 1.342 3.106 2.99v46.844c0 1.649-1.394 2.991-3.106 2.991H10.217c-1.712 0-3.106-1.342-3.106-2.99zm49.778 7.29c0 1.551-1.306 2.812-2.91 2.812H21.195c-1.604 0-2.91-1.26-2.91-2.811v-2.268H44.64c2.833 0 5.138-2.253 5.138-5.023V11.128c.077.018.15.047.233.047h3.968c1.604 0 2.91 1.26 2.91 2.811v45.17z"></path>
  <path d="M38.603 13.206H16.254a1.015 1.015 0 1 0 0 2.032h22.35a1.015 1.015 0 1 0 0-2.032zM38.603 21.333H16.254a1.015 1.015 0 1 0 0 2.032h22.35a1.015 1.015 0 1 0 0-2.032zM38.603 29.46H16.254a1.015 1.015 0 1 0 0 2.032h22.35a1.015 1.015 0 1 0 0-2.032zM28.444 37.587h-12.19a1.015 1.015 0 1 0 0 2.032h12.19a1.015 1.015 0 1 0 0-2.032z"></path>
</svg>
<div class="sr-only">Copy to clipboard</div></button>```javascript
const mix = require("laravel-mix");

// Pull the proxy url from dotenv file
let proxy_url = process.env.BROWSERSYNC_PROXY_URL;
```
```

And then in the browsersync section of your mix file use the variable created above like this:

```
<button class="absolute z-10 flex items-center justify-center w-10 h-10 -translate-y-1/2 bg-gray-300 border rounded-full shadow-sm border-grey-darker -right-4 -top-4" clipboard="" title="Copy to Clipboard" to="" type="button" x-clipboard.raw=".browserSync({
    proxy: proxy_url,
    ghostMode: false,
    notify: {
      styles: {
        top: 'auto',
        bottom: '1rem'
      }
    },
    files: ["src/css/*.css","templates/*.twig", "templates/**/*.twig", "templates/*.js", "templates/**/*.js"]
  });" x-data=""><svg class="h-5 w-5" viewbox="0 0 64 64" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
  <path d="M53.98 9.143h-3.97c-.082 0-.155.028-.232.047V5.023C49.778 2.253 47.473 0 44.64 0H10.217C7.384 0 5.08 2.253 5.08 5.023v46.843c0 2.77 2.305 5.023 5.138 5.023h6.037v2.268c0 2.67 2.216 4.843 4.941 4.843H53.98c2.725 0 4.942-2.173 4.942-4.843v-45.17c0-2.671-2.217-4.844-4.942-4.844zM7.11 51.866V5.023c0-1.649 1.394-2.991 3.106-2.991H44.64c1.712 0 3.106 1.342 3.106 2.99v46.844c0 1.649-1.394 2.991-3.106 2.991H10.217c-1.712 0-3.106-1.342-3.106-2.99zm49.778 7.29c0 1.551-1.306 2.812-2.91 2.812H21.195c-1.604 0-2.91-1.26-2.91-2.811v-2.268H44.64c2.833 0 5.138-2.253 5.138-5.023V11.128c.077.018.15.047.233.047h3.968c1.604 0 2.91 1.26 2.91 2.811v45.17z"></path>
  <path d="M38.603 13.206H16.254a1.015 1.015 0 1 0 0 2.032h22.35a1.015 1.015 0 1 0 0-2.032zM38.603 21.333H16.254a1.015 1.015 0 1 0 0 2.032h22.35a1.015 1.015 0 1 0 0-2.032zM38.603 29.46H16.254a1.015 1.015 0 1 0 0 2.032h22.35a1.015 1.015 0 1 0 0-2.032zM28.444 37.587h-12.19a1.015 1.015 0 1 0 0 2.032h12.19a1.015 1.015 0 1 0 0-2.032z"></path>
</svg>
<div class="sr-only">Copy to clipboard</div></button>```javascript
.browserSync({
    proxy: proxy_url,
    ghostMode: false,
    notify: {
      styles: {
        top: 'auto',
        bottom: '1rem'
      }
    },
    files: ["src/css/*.css","templates/*.twig", "templates/**/*.twig", "templates/*.js", "templates/**/*.js"]
  });
```
```

To me this is an improvement even for projects where I am the lone developer as it is easier for me to copy/paste my mix file from project to project and just update the proxy url setting in the DOTENV file.

## Related Articles

[![Local Development with DDev Thumbnail](https://caffeinecreations.ca/uploads/blog/_680x320_crop_center-center_65_none_ns/ddev-seo.jpg)### Local Development with DDev](https://caffeinecreations.ca/blog/local-development-with-ddev/)

[![Creating a Simple Job Board in Craft CMS Thumbnail](https://caffeinecreations.ca/uploads/hero/_680x320_crop_center-center_65_none_ns/job-board-hero.jpg)### Creating a Simple Job Board in Craft CMS](https://caffeinecreations.ca/blog/creating-a-simple-job-board-in-craft-cms/)

[![Importing Entries into a Multi Lingual Craft CMS Website Thumbnail](https://caffeinecreations.ca/uploads/blog/_680x320_crop_center-center_65_none_ns/import-export.jpg)### Importing Entries into a Multi Lingual Craft CMS Website](https://caffeinecreations.ca/blog/importing-entries-into-a-multi-lingual-craft-cms-website/)
