Cos 302 Web Programming Course Note
Cos 302 Web Programming Course Note
Basic Ideas of the Web The World Wide Web (Web) is a hypermedia system. It has largely achieved the goal
of Tim Berners- Lee, its British inventor, of a universal information space. Tim Berners- Lee invented the
World Wide Web in October 1989.
Thanks to the global reach of the Internet, there is potentially universal access to an enormous volume of
documents over the Internet. However, in many developing countries, access is poor, which raises issues of
disenfranchisement and disempowerment. Many organisations make publicly available collections of
hypermedia documents as part of either their marketing programme, customer service or global operations.
Computer suppliers, for example, now publish very detailed specifications of their products via the Web.
They are cryptographic protocols used to secure data transmitted over the Internet between a
client (browser) and a server (website).
2. Back-End Development: Deals with server-side operations, databases, and application logic, using
languages such as PHP, Python, or Node.js.
Technologies:
Languages – PHP, Python, Node.js, Java, Ruby
Databases – MySQL, PostgreSQL, MongoDB
APIs – REST, GraphQL
Server management – Apache, Nginx
Responsibilities:
Processing form submissions
Authentication and user management
Data storage and retrieval
Business logic (e.g., order processing)
3. Full-Stack Development: Combines both front-end and back-end development skills to build
complete web applications.
This involves both front-end and back-end work.
Full-stack developers handle everything from designing pages to connecting to the database.
Common tools: MERN stack (MongoDB, Express, React, Node), LAMP stack (Linux, Apache,
MySQL, PHP)
Web development is a journey that’s full of twists and turns. Whether you're working on a personal project
or a large-scale website for a business, you'll quickly encounter a wide range of challenges that will test your
skills and patience. Knowing what obstacles lie ahead can help you prepare and respond effectively. So, let’s
dive into the 9 biggest web development challenges you’re likely to face and how to tackle them
1. Cross-Browser Compatibility
when your website looks perfect in Chrome, but a complete mess in Firefox or Safari? That’s cross-
browser compatibility, one of the most common web development challenges. Different browsers use
different rendering engines, which can interpret your website’s code in various ways, leading to
inconsistencies.
Each browser has its own unique set of rules and ways to interpret HTML, CSS, and JavaScript.
While one browser might perfectly understand a certain code structure, another browser could
completely misinterpret it.
To handle this issue ensuring consistent appearance and functionality across different web browsers.
Utilize frameworks like Bootstrap that are built with browser compatibility and Regularly test your
website on various browsers.
2. Mobile Responsiveness
With more users accessing websites from mobile devices than desktops, it’s vital to ensure your
website adapts well to smaller screens. Poor mobile optimization leads to a bad user experience and
can cost you visitors.
Designing for mobile responsiveness has become one of the most significant web dev challenges for
developers.
Best practices for responsive design,
Adopt a mobile-first approach: Start by designing for smaller screens and scale up for larger devices.
Use flexible grid layouts: CSS Grid and Flexbox can help you create layouts that adjust dynamically
to screen sizes.
Optimize images and media: Ensure media files are resized and compressed for quick loading on
mobile devices.
3. Website Speed Optimization
In the fast-paced digital world, speed matters. If your website takes more than three seconds to load,
you risk losing visitors. Website speed optimization remains a critical web development challenge
because of how it impacts user experience and SEO rankings.
The impact of slow websites on user experience is no one likes waiting around for a site to load.
Slow websites lead to higher bounce rates, lower engagement, and ultimately, lost conversions. Plus,
search engines like Google penalize slow sites by pushing them down in search rankings.
Solution is to Optimize images, minify CSS and JavaScript files, leverage caching, and use Content
Delivery Networks (CDNs) to enhance load times. A CDN is a network of servers located around the
world. When someone visits your website, the CDN delivers files from the nearest server, reducing
distance and latency.
4. Security Vulnerabilities
The internet is not as secure as we’d like it to be, and web developers are always at the forefront of
the fight against security vulnerabilities. Threats like SQL injections, cross-site scripting (XSS), and
data breaches pose serious risks.
Common web development security threats are.
SQL Injection: Attackers manipulate your database queries to gain access to sensitive data.
Cross-Site Scripting (XSS): Hackers inject malicious scripts into your website to Steal cookies,
session tokens, or other sensitive data.
Brute Force Attacks: These attempts to guess passwords can compromise user accounts.
Implement SSL certificates to encrypt data transmission. Sanitize user inputs to prevent SQL
injection and XSS attacks. Regularly update your website’s software and plugins to avoid
vulnerabilities.
5. SEO Optimization
SEO isn’t just about keywords.
it’s about how your website is structured and presented to search engines. Poor SEO can lead to
lower rankings, even if your website content is top-notch.
SEO considerations during web development
From the very beginning, SEO should be a part of your development process. Search engines crawl
websites for specific elements like clean code, mobile-friendliness, and fast load times.
Solution Is to Integrating SEO into your website structure Use semantic HTML tags to help search
engines understand your content. Ensure your site is mobile-responsive and fast-loading. Optimize
meta tags, titles, and descriptions for better visibility on search engines.
6. Scalability
As your website grows, can your infrastructure (server) handle it? Scalability is a common web dev
challenge that often gets overlooked during the initial development phases.
Planning for website growth If your site suddenly experiences a surge in traffic, you need to make
sure your server and codebase can accommodate it without crashing.
Developing scalable architecture
Use cloud services like AWS or Google Cloud to easily scale your server needs.
Implement load balancers to distribute traffic evenly across your servers.
Write efficient, clean code to minimize performance bottlenecks.
8. Content Management
Your website isn’t static. Content will need to be updated, changed, or added regularly, and having a
smooth content management system (CMS) is critical to ensure these updates happen without
hiccups.
HTML Basics
HTML Structure
HTML Links
HTML Images
HTML Lists
🔹 HTML Tables
HTML Forms
➡ text, email, password, number, checkbox, radio, date, file, submit, reset are common input types
HTML Multimedia
HTML Attributes
HTML Comments
🔹 CSS Basics
🔹 CSS Syntax
🔹 CSS Selectors
🔹 Box Model
🔹 Backgrounds
🔹 Borders
➡ display defines how elements are rendered: block, inline, inline-block, flex, grid, none
➡ visibility: hidden hides the element but retains space
➡ position:
➡ static (default)
➡ relative (moves relative to its position)
➡ absolute (relative to nearest positioned ancestor)
➡ fixed (relative to viewport)
➡ sticky (sticks during scroll)
➡ top, right, bottom, left work with positioning
🔹 Flexbox
🔹 CSS Grid
➡ Colors:
➡ Named (e.g. red)
➡ Hex (#ff0000)
➡ RGB (rgb(255,0,0))
➡ RGBA (with transparency)
➡ Units:
➡ px, em, rem, %, vh, vw
Introduction to events
Events are things that happen in the system you are programming, which the system tells you about so your
code can react to them. For example, if the user clicks a button on a webpage, you might want to react to
that action by displaying an information box. In this article, we discuss some important concepts
surrounding events, and look at the fundamentals of how they work in browsers.
What is an event?
Events are things that happen in the system you are programming — the system produces (or "fires") a
signal of some kind when an event occurs, and provides a mechanism by which an action can be
automatically taken (that is, some code running) when the event occurs. Events are fired inside the browser
window, and tend to be attached to a specific item that resides in it. This might be a single element, a set of
elements, the HTML document loaded in the current tab, or the entire browser window. There are many
different types of events that can occur.
For example:
The user selects, clicks, or hovers the cursor over a certain element.
The user presses a key on the keyboard.
The user resizes or closes the browser window.
A web page finishes loading.
A form is submitted.
A video is played, paused, or ends.
An error occurs.
header:
Usually a big strip across the top with a big heading, logo, and perhaps a tagline. This usually stays the same
from one page of a website to another.
navigation bar:
Links to the site's main sections; usually represented by menu buttons, links, or tabs. Like the header, this
content usually remains consistent from one webpage to another — having inconsistent navigation on your
website will just lead to confused, frustrated users. Many web designers consider the navigation bar to be
part of the header rather than an individual component, but that's not a requirement; in fact, some also argue
that having the two separate is better for accessibility, as screen readers can read the two features better if
they are separate.
main content:
A big area in the center that contains most of the unique content of a given webpage, for example, the video
you want to watch, or the main story you're reading, or the map you want to view, or the news headlines, etc.
This is the one part of the website that definitely will vary from page to page!
sidebar:
Some peripheral info, links, quotes, ads, etc. Usually, this is contextual to what is contained in the main
content (for example on a news article page, the sidebar might contain the author's bio, or links to related
articles) but there are also cases where you'll find some recurring elements like a secondary navigation
system.
footer:
A strip across the bottom of the page that generally contains fine print, copyright notices, or contact info. It's
a place to put common information (like the header) but usually, that information is not critical or secondary
to the website itself. The footer is also sometimes used for SEO purposes, by providing links for quick
access to popular content.
javascript
JavaScript is a scripting or programming language that allows you to implement complex features on web
pages —
every time a web page does more than just sit there and display static information for you to look at —
displaying timely content updates, interactive maps, animated 2D/3D graphics, scrolling video jukeboxes,
etc. —
you can bet that JavaScript is probably involved. It is the third layer of the layer cake of standard web
technologies, two of which (HTML and CSS)
HTML is the markup language that we use to structure and give meaning to our web content, for example
defining paragraphs, headings, and data tables, or embedding images and videos in the page.
CSS is a language of style rules that we use to apply styling to our HTML content, for example setting
background colors and fonts, and laying out our content in multiple columns.
JavaScript is a scripting language that enables you to create dynamically updating content, control
multimedia, animate images, and pretty much everything else. (Okay, not everything, but it is amazing what
you can achieve with a few lines of JavaScript code.)
Store useful values inside variables., we ask for a new name to be entered then store that name in a variable
called name.
Operations on pieces of text (known as "strings" in programming). In the above example we take the string
"Player 1: " and join it to the name variable to create the complete text label, e.g., "Player 1: Chris".
Running code in response to certain events occurring on a web page. We used a click event in our example
above to detect when the label is clicked and then run the code that updates the text label.
And much more!
What is even more exciting however is the functionality built on top of the client-side JavaScript language.
So-called Application Programming Interfaces (APIs) provide you with extra superpowers to use in your
JavaScript code.
APIs are ready-made sets of code building blocks that allow a developer to implement programs that would
otherwise be hard or impossible to implement. They do the same thing for programming that ready-made
furniture kits do for home building — it is much easier to take ready-cut panels and screw them together to
make a bookshelf than it is to work out the design yourself, go and find the correct wood, cut all the panels
to the right size and shape, find the correct-sized screws, and then put them together to make a bookshelf.
Introduction to Web Security
When information transmitted over the web, not only does the data have reach its destination, but it needs to
arrive intact and uncorrupted (integrity), and other people should be prevented from seeing it
(confidentiality). The nature of the Internet makes directing information to reach its destination relatively
trivial, but ensuring its integrity and confidentiality is more difficult. Fortunately, encryption algorithms
have made both integrity and confidentiality feasible. Additionally, users like to know that the information
they receive is genuine (authentication) and that the sender of the information cannot deny that they sent it
(non-repudiation).
The web is an interconnection of networks. Everybody uses the Internet to transfer data and that the data has
value (and cost), and so it is a subject to theft. Types of information that are stolen include personal user's
information, commercial or technical data (including commercial secrets and intellectual property), or even
security and military information. Leaking of such information can stay undiscovered for months, if not
years, doing damage to people that sent information and also to third parties.
Common vulnerabilities
Some of the top five security vulnerabilities are SQL injection; buffer overflow; sensitive data exposure
broken authentication and session management; and security misconfiguration.
These are briefly discussed below.
SQL Injection
SQL injection is a technique where malicious users can inject SQL commands into an SQL statement, via
web page input. Injected SQL commands can alter SQL statement and compromise the security of a web
application. A Database is the heart of many web-applications and is used to store information needed by the
application, such as, credit card information, customer demographics, customer orders, client preferences,
etc. SQL Injections happen when a developer accepts user input that is directly placed into a SQL Statement
and doesn’t properly validate and filter out dangerous characters.
This can allow an attacker to alter SQL statements passed to the database as parameters and enable her to not
only steal data from your database, but also modify and delete it. A database is vulnerable to SQL injections
when user input is either incorrectly filtered for string literal escape characters embedded in SQL statements
or user input is not strongly typed. SQL injection attacks are also known as SQL insertion attacks.
Buffer Overflow
A buffer overflow vulnerability condition exists when an application attempts to put more data in a buffer
than it can hold. Writing outside the space assigned to buffer allows an attacker to overwrite the content of
adjacent memory blocks causing data corruption, crash the program, or the execution of an arbitrary
malicious code.