A common task faced by web designers is dealing with the constant workflow of editing web pages and reviewing their changes. With the large number of web browsers in the market, it can be tedious to keep them all in sync as changes are made. VS2015 seeks to address this with the advent of the Browser Link feature. The Browser Link feature allows you to select any number of browsers available on your development machine, and have them refreshed after making changes to your web pages. This feature makes it very easy to make changes to your website, and to preview them across your site's supported browsers in a streamlined way.
In this recipe, we will look at how to set up Browser Link, and how it can help you with your projects.
You can use Visual Studio Express 2015 for Web, Visual Studio 2015 Community Edition, or any of the premium editions for this recipe. You should also make available all of the web browsers you plan to use (Google Chrome, Mozilla Firefox, and so on) before we start. If you would like to just see how the feature works first, Internet Explorer will work fine.
We will start this recipe by enabling support for Browser Link, and then we will see it in action by performing the following steps:
Web.config
file, you will see the following error message on your Browser Link Dashboard window:compilation
element is set to true
, as shown in the following screenshot:Visual Studio is able to make this feature work by injecting a snippet of JavaScript into the web pages served by Visual Studio's internal web server. This code is added transparently behind the scenes, and does not affect your source in any way (it is not saved to the disk or entered into your source control system). The following screenshot shows the code that is added:
Browser Link is tied to running your site through Visual Studio in the Debug mode; it turns itself off when switching to the Release mode.
However, there may be situations where you want to absolutely guarantee that Browser Link is not running—perhaps you are tracking down a particularly nasty bug, and want to eliminate all outside factors. The following code fragments added to your project's Web.Config
file under the appSettings
tag can force Browser Link to always be ON (true
) or always OFF (false
), depending on your needs:
<system.web> <compilation debug="false" targetFramework="4.6.1" /> </system.web>
Separately, the following change to appSettings
should be paired with the preceding change:
<appSettings> <add key="vs:enableBrowserLink" value="false"/> </appSettings>
To ensure that Browser Link correctly displays the static HTML files, add the following to your Web.config
file in the handlers section under system.webServer
:
<add name="Browser Link for HTML" path="*.html" verb="*" type="System.Web.StaticFileHandler, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" resourceType="File" preCondition="integratedMode" />
Note that you should only include this while developing, as it should not be enabled for production use due to performance considerations.
18.116.36.192